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
Forum Updated to NodeBB v4.3 + New Features

Triggering Button By Pressing Enter KEy

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 2.7k 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 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
    • YunusY Offline
      YunusY Offline
      Yunus
      wrote on 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 last edited by
        #3

        yes I tried,but it is not working

        J.HilkJ 1 Reply Last reply
        0
        • ashajgA Offline
          ashajgA Offline
          ashajg
          wrote on last edited by ashajg
          #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

            yes I tried,but it is not working

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on 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

            • Login

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