KeyReleaseEvent() not picked up after opening file chooser with shortcut Ctrl+O
-
Hello,
I have implemented a Ctrl+wheelEvent for a zoom action on a QGraphicsView. I manage this by picking up the keyPressEvent(), set a self.ctrl = True value and on keyReleaseEvent() I set the self.ctrl = False.
It works correctly except when I open the file chooser with Ctrl+O, in which case the keyPressEvent() is picked up, but the keyReleaseEvent() is not. Because of this the self.ctrl remains True and a wheelEvent alone is then able to activate the zoom action without the Ctrl key being pressed.
I work around this by setting the self.ctrl value to False right after the file chooser has done its job, but I find this an ugly way to solve the issue.
So did I implement this the wrong way? What's the best practice? Thanks.
-
Hi Benjamin :)
You can use
@
if (event->modifiers() & Qt::ShiftModifier) {
// Shift is pressed
}
@in your wheelEvent.
-
Oh, you would obviously want to use
@
event->modifiers() & Qt::ControlModifier
@Sorry.