Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Triggering Button By Pressing Enter KEy
QtWS25 Last Chance

Triggering Button By Pressing Enter KEy

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AbhishekBlaze
    wrote on 6 Feb 2019, 04:38 last edited by
    #1

    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!!

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      Yunus
      wrote on 6 Feb 2019, 05:23 last edited by
      #2

      @AbhishekBlaze Hi. Did you try this method:

      Keys.onEnterPressed: (your function here)

      Maybe this link can help you:

      http://doc.qt.io/qt-5/qtquick-usecase-userinput.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AbhishekBlaze
        wrote on 6 Feb 2019, 09:34 last edited by
        #3

        yes I tried,but it is not working

        J 1 Reply Last reply 6 Feb 2019, 11:37
        0
        • A Offline
          A Offline
          ashajg
          wrote on 6 Feb 2019, 11:13 last edited by ashajg 2 Jun 2019, 11:15
          #4

          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")
              Rectangle
              {   width:200
                  height:200
                  anchors.centerIn: parent
                  color:"red"
                  focus: true
                  Keys.onPressed:
                  {
                      if(event.key === Qt.Key_Down)
                      {
                      console.log("success!!!")
                      }
          
                  }
          
              }
          }
          

          output:

          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...

          1 Reply Last reply
          1
          • A AbhishekBlaze
            6 Feb 2019, 09:34

            yes I tried,but it is not working

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 6 Feb 2019, 11:37 last edited by
            #5

            @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.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1

            1/5

            6 Feb 2019, 04:38

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved