How can I make a default QPushButton respond to ENTER?
-
@Ronel_qtmaster I am sorry I don't understand what you are saying. Is there no way to make the button respond to ENTER? what if I set a shortcut?
wrote on 22 Mar 2024, 11:38 last edited by@jdent i mean setDefault will not work when there is a focus in the LineEdit.Appart from that it will work.If you add a shortcut it will work as well
-
@jdent i mean setDefault will not work when there is a focus in the LineEdit.Appart from that it will work.If you add a shortcut it will work as well
wrote on 22 Mar 2024, 11:45 last edited by jdent@Ronel_qtmaster ok. How can I set a shortcut for the ENTER key?
I triedsearchButton->setShortcut(QKeySequence::StandardKey::)
but there is no key for ENTER or RETURN!
-
@Ronel_qtmaster ok. How can I set a shortcut for the ENTER key?
I triedsearchButton->setShortcut(QKeySequence::StandardKey::)
but there is no key for ENTER or RETURN!
wrote on 22 Mar 2024, 11:53 last edited by@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
-
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
wrote on 22 Mar 2024, 12:17 last edited by@Ronel_qtmaster I tried it - no results.
In MFC (Microsoft Foundation Classes) you can do this, I can't see why we can't do it in Qt...
There must be a way!!When I press ENTER when inside the line edit, can't I take that keystroke and invoke the Search button?
-
@Ronel_qtmaster I tried it - no results.
In MFC (Microsoft Foundation Classes) you can do this, I can't see why we can't do it in Qt...
There must be a way!!When I press ENTER when inside the line edit, can't I take that keystroke and invoke the Search button?
-
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
wrote on 22 Mar 2024, 13:09 last edited by@Ronel_qtmaster said in How can I make a default QPushButton respond to ENTER?:
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
See my discussion with @Chris-Kawa on this in https://forum.qt.io/topic/155461/qlineedit-returnpressed-when-something-else-has-a-key_return-shortcut. It might be worth trying
Qt::Key_Return
here, I suspect what you call the Enter key is what Qt calls the Return key. But it may be that those two are interchangeable, not sure.It can certainly be done with a shortcut if you want, but I (think I) prefer @jsulm's suggestion of connecting
returnPressed
. -
@Ronel_qtmaster said in How can I make a default QPushButton respond to ENTER?:
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
See my discussion with @Chris-Kawa on this in https://forum.qt.io/topic/155461/qlineedit-returnpressed-when-something-else-has-a-key_return-shortcut. It might be worth trying
Qt::Key_Return
here, I suspect what you call the Enter key is what Qt calls the Return key. But it may be that those two are interchangeable, not sure.It can certainly be done with a shortcut if you want, but I (think I) prefer @jsulm's suggestion of connecting
returnPressed
. -
-
@Ronel_qtmaster said in How can I make a default QPushButton respond to ENTER?:
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
See my discussion with @Chris-Kawa on this in https://forum.qt.io/topic/155461/qlineedit-returnpressed-when-something-else-has-a-key_return-shortcut. It might be worth trying
Qt::Key_Return
here, I suspect what you call the Enter key is what Qt calls the Return key. But it may be that those two are interchangeable, not sure.It can certainly be done with a shortcut if you want, but I (think I) prefer @jsulm's suggestion of connecting
returnPressed
.wrote on 22 Mar 2024, 14:14 last edited by@JonB Thanks for the hint
-
@Ronel_qtmaster said in How can I make a default QPushButton respond to ENTER?:
@jdent did you try pushButton->setShortcut(QKeySequence(Qt::Key_Enter));
See my discussion with @Chris-Kawa on this in https://forum.qt.io/topic/155461/qlineedit-returnpressed-when-something-else-has-a-key_return-shortcut. It might be worth trying
Qt::Key_Return
here, I suspect what you call the Enter key is what Qt calls the Return key. But it may be that those two are interchangeable, not sure.It can certainly be done with a shortcut if you want, but I (think I) prefer @jsulm's suggestion of connecting
returnPressed
.wrote on 25 Mar 2024, 06:57 last edited by@JonB said in How can I make a default QPushButton respond to ENTER?:
I suspect what you call the Enter key is what Qt calls the Return key
You might want to connect both Enter and Return. If I'm not mistaken, Enter is the key located in the NumPad area.
-
@JonB said in How can I make a default QPushButton respond to ENTER?:
I suspect what you call the Enter key is what Qt calls the Return key
You might want to connect both Enter and Return. If I'm not mistaken, Enter is the key located in the NumPad area.
wrote on 25 Mar 2024, 08:20 last edited by JonB@SimonSchroeder See the discussion around https://forum.qt.io/topic/155461/qlineedit-returnpressed-when-something-else-has-a-key_return-shortcut/16 for the pointlessness/potential evilness of the NumPad Enter key ;-)
13/13