Search code examples
pythonpyqt4pyqt5

How to have default and custom wheelEvent


I have this function that overwrites default behaviour of wheelEvent (changes font sizes in QTextEdit, behaves like zoom in/out), but since that class is inheriting from QTextEdit I have lost default wheel behaviour which is scrolling when the mouse is anywhere inside it.

So my question is: How to have normal behaviour for wheel event, and "something_else" for Ctrl + wheel event.

Note: function called with Ctrl modifier is made I just don't know how to combine it with normal behaviour.

 def wheelEvent(self, event):

        if (event.modifiers() & QtCore.Qt.ControlModifier):
            self.bindWheel(event)

        else:
            pass

Solution

  • You can call the default implementation of your QTextEdit super class. Assuming you are using Python 3:

    def wheelEvent(self, event):
        if (event.modifiers() & QtCore.Qt.ControlModifier):
            self.bindWheel(event)
        else:
            super().wheelEvent(event)