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. Checking for letters pressed when mouse is pressed
Forum Updated to NodeBB v4.3 + New Features

Checking for letters pressed when mouse is pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
mousepresseventkeypressevent
6 Posts 4 Posters 4.8k Views 3 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.
  • L Offline
    L Offline
    LancelotPops
    wrote on 1 Jun 2017, 12:19 last edited by
    #1

    Hi everyone !

    I'm developing an application using Qt in C++.

    When there is a mouse click, I would like to check if there are letters pressed on the keyboard. So far, I found solutions when the keys pressed are specific ones like Shift, Control .. but not when a letter is pressed.

    Do you have any advice for me ?

    PS: Sorry if this topic isn't in the right category, I wasn't sure where to post it.

    Thank you !

    Sandra

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eligijus
      wrote on 1 Jun 2017, 12:34 last edited by
      #2

      Combine

      virtual void	mousePressEvent(QMouseEvent * event)
      

      and

      virtual void	keyPressEvent(QKeyEvent * event)
      
      1 Reply Last reply
      0
      • E Offline
        E Offline
        Eddy
        wrote on 1 Jun 2017, 12:36 last edited by
        #3

        Hi @LancelotPops ,

        welcome to the Qt forum.

        Did you have a look at queryKeyboardModifiers ?

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        1
        • L Offline
          L Offline
          LancelotPops
          wrote on 1 Jun 2017, 12:56 last edited by
          #4

          Indeed, my application is a QSlicerApplication (I'm developing a module in 3DSlicer) and I'm not sure I can use exactly the same solutions as if I were only working with Qt.

          I tried this :

          when leftButtonPressEvent :

          Qt::KeyboardModifiers modifier = qSlicerApplication::application()->keyboardModifiers();
               if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier) == true) {
                  std::cout << "shift pressed" << std::endl;
               }
          

          This works very well ... but it only works for specific keys (Control, Shift ..), is there something like that but working for letters pressed ?

          1 Reply Last reply
          1
          • E Offline
            E Offline
            Eddy
            wrote on 1 Jun 2017, 13:08 last edited by Eddy 6 Jan 2017, 13:08
            #5

            Hi,

            this topic may be of interest to determine the keys.

            Hope it helps,

            Eddy

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply
            1
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 1 Jun 2017, 20:39 last edited by
              #6

              Hi and welcome to devnet,

              Can you explain why do you need to know whether a letter is currently pressed ?

              A long press on such a key usually triggers the auto-repeat of the system so it might make things a bit more difficult.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              3/6

              1 Jun 2017, 12:36

              • Login

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