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. [SOLVED] How to detect SHIFT key release event?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to detect SHIFT key release event?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.0k 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.
  • X Offline
    X Offline
    xtingray
    wrote on last edited by
    #1

    Hi!

    I am trying to detect the moment when the user release the SHIFT key from my application. The thing is that the keyReleaseEvent() is actually called when I release that modifier, but for now I can't figure out how to detect that the modifier really was SHIFT instead other key.

    @
    void MyClass::keyReleaseEvent(QKeyEvent *event)
    {
    qDebug() << "MyClass::keyReleaseEvent() -> key: " << event->text();
    qDebug() << "MyClass::keyReleaseEvent() -> modifiers(): " << event->modifiers();
    if (event->modifiers() == Qt::ShiftModifier) { // This if is NOT working :(
    qDebug() << "MyClass::keyReleaseEvent() -> key unpressed: SHIFT";
    }
    }
    @

    Any suggestion? Thanks!


    Qt Developer

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One thing that you could do would be to store the modifier(s) on keyPressEvent and check against them in keyReleaseEvent.

      Hope it helps

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

      D 1 Reply Last reply
      1
      • X Offline
        X Offline
        xtingray
        wrote on last edited by
        #3

        Simple but handy. Shame on me!

        Thanks! :)


        Qt Developer

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Some times the solution can be simple :)

          You're welcome !

          Happy coding :)

          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
          • SGaistS SGaist

            Hi,

            One thing that you could do would be to store the modifier(s) on keyPressEvent and check against them in keyReleaseEvent.

            Hope it helps

            D Offline
            D Offline
            dschiller
            wrote on last edited by
            #5

            @SGaist Can you please give a small code example ?

            D 1 Reply Last reply
            0
            • D dschiller

              @SGaist Can you please give a small code example ?

              D Offline
              D Offline
              dschiller
              wrote on last edited by dschiller
              #6

              Found a solution.

              def _event(self, event: QEvent):
              
                  if event.type() == event.Type.KeyRelease:
              
                      # region Release SHIFT Key
                      if QKeyEvent(event).key() == Qt.Key.Key_Shift and self.shift_key_locked:
                          self.shift_key_locked = False
                      # endregion
              
                  if event.type() == event.Type.KeyPress:
              
                      # region SHIFT Key
                      if QKeyEvent(event).modifiers() == Qt.KeyboardModifier.ShiftModifier and not self.shift_key_locked:
                          self.shift_key_locked = True
                      # endregion
              
              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