I have a Qt 5 application with a 3D viewport which the user can navigate around when holding RClick and using WASDQE. I'd like to make it so holding Ctrl slows the camera movement down, however doing this will activate shortcuts.
Is it possible to disable and enable all shortcuts such that I can disable them while mouse buttons are down?
I've tried installing an event filter onto my main window however shortcuts are still activated (Despite even returning true for every event type).
I ended up creating an event filter for my 3D viewport widget to check for mouse presses. Each time I encounter these events (As well as key release events) I then call a function (
checkShortcutsEnabled()
) on my main window to switch the shortcut content depending on if no buttons are pressed or not.The reason why I also check for key release events is to only re-enable shortcuts when no keyboard modifiers are held down (Such that if you release your mouse buttons before keyboard keys, you don't accidentally trip a shortcut)
Shortcuts default to
Qt::WindowShortcut
, meaning they can be activated anywhere in the window. When mouse buttons are down over the viewport, I switch this tempoararily toQt::WidgetShortcut
, which only means they can be activated if the widget received the shortcuts (But not the viewport widget, which is a child of my main window). It's a nicer alternative to disabling/re-enabling them as I don't have to tinker around with saving disabled state, as well as toolbar buttons going grey.The main window class
The event filter class