Important: Please read the Qt Code of Conduct -

How to customize/create a Wheel Event?

  • Hi guys!
    I was trying to create a wheel event for my widget in PyQt5. I did it in Qt(C++), but so far I have no idea in PyQt.
    Please help me. Thanks in advance!

  • @SoleyRan
    Did you try translating your C++ code to PyQt5?

  • @JonB Yes, I tried to translate the C++ code to PyQt5, but it seems the params of QWheelEvent in PyQt5 is not the exactly same as Qt. ( I am not sure...)

    I got these info:
    Qt(C++): QWheelEvent::QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized)
    PyQt5: class QWheelEvent(pos, globalPos, pixelDelta, angleDelta, buttons, modifiers, phase, inverted[, source=Qt.MouseEventNotSynthesized])

  • @SoleyRan
    Trying to read through those two lines not presented in code tags here, seems to me they are the same.

  • Banned

    okay the PyQt5 QWheelEvent is documented and pretty straight forward as to how to use it -- that is if I understand what you are asking since you did not provide an MRE to make it more clear

    def self.wheelEvent(self, WheelEvent):

    that is how you would define it within the Object that is handling the Wheel Event such as your QMainWindow or whatever you are using for main GUI -- then all you have to do is handle that Wheel Event correct which is also covered in the documentation

    Or are you actually trying Emit a QWheelEvent if this then you need to look into defining the QWheelEvent and than simply emit the WheelEvent once you have created it and set the parameters you wish to set which you do not have to do all at once as most widgets have -- setThis methods -- thus you would start here

    WheelEvent = QWheelEvent()