How set mouse scrolling as a shortcut
-
I have a Qt application and I want to set mouse wheel as a shortcut.
Now when I turn off possibility of use shortcuts I can't use keys but still the mouse wheel works. How can I block mouse wheel when I turn off possibility of use shortcuts?
@Mary02 You can implement an event filter, see https://doc.qt.io/qt-5/eventsandfilters.html
-
Thanks, but I have a problem with it. I add eventFilter in file where is my object:
bool obj::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Wheel) { return true; } return QObject::eventFilter(object, event); }and now mouse wheel is totally blocked. Bool variable which says if shortcuts are on/off is in different file and it's private. How can I add this variable to my eventFilter?
-
Thanks, but I have a problem with it. I add eventFilter in file where is my object:
bool obj::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Wheel) { return true; } return QObject::eventFilter(object, event); }and now mouse wheel is totally blocked. Bool variable which says if shortcuts are on/off is in different file and it's private. How can I add this variable to my eventFilter?
@Mary02 said in How set mouse scrolling as a shortcut:
How can I add this variable to my eventFilter?
The Qt way is to use signals/slots to communicate the change of the shortcut changes to whatever part of your app needs to know.