How can I make a default QPushButton respond to ENTER?
-
@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 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 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
. -
-
@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.
-
@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 ;-)