Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How we can set enter key to a widget so that while pressing enter a click event should occur?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.8k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    the widget should respond to enter key.

    Pratik Agrawal

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Are you talking from standard or custom widgets?

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

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

        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?

        Pratik Agrawal

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            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.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              pratik041
              wrote on last edited by
              #6

              ok thank's

              Pratik Agrawal

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0

                • Login

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