Re: Form with default button
Quote:
1-"Add" button is a default button.
use addButton->setFocus(true).
Quote:
2-When I click "Enter", the action "Add" is executed.
Read about signals and slots
Re: Form with default button
Hi
this is difficult to understand.
Quote:
2-When I click "Enter", the action "Add" is executed.
is "Enter" a new button ? and on click event u are expecting "Add" button should behave as clicked ?
Re: Form with default button
Hi all,
My button "Add" is already connected with the expected slot.
I just would like that this slot is executed too when the button is enable and when the user hits the key "Enter".
Here is an example of screenshot:
http://skrooge.org/node/4
Re: Form with default button
QPushButton::setDefault() is the way to go, but the parent widget of the button must be focused. Maybe QWidget::setFocusProxy() can help you handle the focus correctly among your widgets.
Re: Form with default button
Quote:
Originally Posted by
mattc
QPushButton::setDefault() is the way to go, but the parent widget of the button must be focused. Maybe QWidget::setFocusProxy() can help you handle the focus correctly among your widgets.
I already tried, but, as documented, this function is working only on QDialog.
It's not my case.
How can I do ?
Re: Form with default button
A button is not triggered with Enter key. You need to press spacebar.
If you want to trigger the button on Enter key, you will need to install filter on events or override keyPressEvent. You can then call click()
Re: Form with default button
You are right, it works only for QDialogs.
Some things you might try:
1) as aamer4yu said, use QPushButton::setFocus(true) or QWidget::setFocusProxy() to force focus on the button
2) create a QShortcut, connect to the activated() signal and then call QPushButton->animateClick()
3) override QWidget::keyPressEvent() in the button's parent, detect the Enter key and then call QPushButton->animateClick()