[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!
-
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
-
Some times the solution can be simple :)
You're welcome !
Happy coding :)
-
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