I am developing an app.I would like there to be an option to zoom in and out. to do this I would like to have the program get when the control key is clicked and the mouse is being scrolled at the same time, and zoom accordingly(scroll up for zoom in, and scroll down for zoom out) I've been doing a lot of searching and reading,but only found ways to get a control press and a mouse click-event, not a mouse scroll-event. I also found a way to get a mouse scroll but couldn't get it to work with just control press. - and to ignore all other presses.
Could anyone suggest something to help me???
It depends a bit on the structure of your application.
One way to get scroll-events is to add a wheelEvent handler to your Widget
def wheelEvent(self, QWheelEvent):
modifiers = QtGui.QApplication.keyboardModifiers()
if modifiers == QtCore.Qt.ControlModifier:
# do your processing
Another approach could be to install an eventFilter in the component where you want to intercept the scroll-events by
component.viewport().installEventFilter(self)
(maybe you have to install the event filter on the component itself iso on the viewport).
and self has an eventFilter function like
def eventFilter(self, qobject, event):
if (event.type() == QtCore.QEvent.Wheel) :
modifiers = QtGui.QApplication.keyboardModifiers()
if modifiers == QtCore.Qt.ControlModifier:
#do some scaling stuff
return True
return False
else:
# standard event processing
return False
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With