Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, September 2002
lineEdit returnPressed signals being routed to PushButton slots


Message 1 in thread


<<< text/html: EXCLUDED >>>

Attachment: prob.zip
Description: Binary data


Message 2 in thread

On Wed, 4 Sep 2002 13:55:40 -0700
"Volz, Bill (WRVO)" <WRVO@ChevronTexaco.com> wrote:

> I've attached a short program that doesn't behave the way I expect. It
> contains a push button with the clicked() signal connected to a slot
> that changes the label. There is also a line edit that has the
> returnPressed() signal connected to anther signal that does nothing.
> When you run the program and put the cursor in the line edit widget and
> press return, the slot for the push button is activated. The slot
> connected to the line edit gets the signal, but so does the push button.
> 
> Why?

(After a quick look at the code, short debug test and experimentation).

Because the QPushButton has been created a child of a QDialog, its
autoDefault property is set to true by default (this is documented in the
QDialog and QPushButton docs). Meaning that since it is the only button on
the dialog, it is made default when the dialog shows up, and therefore it
gets activated when you press Return in the dialog.

You can avoid this by setting the autoDefault property for the button to
false in Designer or calling setAutoDefault(false) on the QPushButton in
your code.

-- 
 [ signature omitted ] 

Message 3 in thread

On Thu, 5 Sep 2002 08:41:57 +0000
Matthieu Dazy <dazy@t-surf.com> wrote:

> You can avoid this by setting the autoDefault property for the button to
> false in Designer or calling setAutoDefault(false) on the QPushButton in
> your code.

Additional note : if you do not need QDialog-specific features like the
reject/accept slots, another solution is to use another class (e.g. QFrame
or QWidget, Widget template in Designer) as a base for your window.

-- 
 [ signature omitted ]