Important: Please read the Qt Code of Conduct -

[SOLVED] How to detect SHIFT key release event?

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

  • Lifetime Qt Champion


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

    Hope it helps

  • Simple but handy. Shame on me!

    Thanks! :)

  • Lifetime Qt Champion

    Some times the solution can be simple :)

    You're welcome !

    Happy coding :)

Log in to reply