Important: Please read the Qt Code of Conduct -

Triggering Button By Pressing Enter KEy

  • In my Application I have lots of button and every button has associated function and these function executes when the user click on the button with the mouse. Now I need to trigger one of the button click when the user presses the enter key. Is there any method to do this? How can I do it ? Please Help!!

  • @AbhishekBlaze Hi. Did you try this method:

    Keys.onEnterPressed: (your function here)

    Maybe this link can help you:

  • yes I tried,but it is not working

  • hi @AbhishekBlaze
    this is a small example !!!

    guess you were asking for something like this...
    in this program I am printing success when down key is pressed.

    import QtQuick 2.9
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        {   width:200
            anchors.centerIn: parent
            focus: true
                if(event.key === Qt.Key_Down)


    16:39:58: Starting C:\ASHISH\PROGRAMS\build-key-Desktop_Qt_5_11_2_MinGW_32bit-Debug\debug\key.exe...
    QML debugging is enabled. Only use this in a safe environment.
    qml: success!!!

    please check if you have set the focus true...

  • Moderators

    @AbhishekBlaze said in Triggering Button By Pressing Enter KEy:

    yes I tried,but it is not working

    IIRC, if you don't do this in the root element of your QML-Scene, than the Item has to have the activeFocus property set to true. As in the element has to accept focus and has to have the focus or the event will be ignored.

Log in to reply