How we can set enter key to a widget so that while pressing enter a click event should occur?



  • the widget should respond to enter key.



  • Are you talking from standard or custom widgets?

    You could subclass the widget, overwrite the keyPressEvent and do it there.



  • but inside key press event does i have to use Qobject::connect to make the enter to respond or some other way can you give example?



  • I guess subclassing you have to intercept the enter key and manually call the function that implements the slot "clicked" in your button, or "triggered" if it is an action, and so on.



  • I'm a bit confused.
    If you have for example a QPushButton and want it to emit a clicked signal in case a B key is pressed, you overwrite keyPressEvent, make an if to check for the B and then emit the needed signal.



  • ok thank's



  • You can just make your button the default button on the form.
    @
    QButton::setDefault(true);
    @

    That will make it respond to an Enter click anywhere in the form, except when the currently focussed widget accepts the enter key itself (like a QPlainTextEdit widget).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.