Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get pixelDelta from QWheelEvent in Qt5

I upgraded from Qt4 to Qt5 (PyQt, to be specific) and QWheelEvent broke for me - it returns empty pixelDelta(), but phase is at 2 (default). I am on Win 7, so the warning about phases shouldn't apply to me. When I run this code:

from PyQt5 import QtWidgets


class Q(QtWidgets.QLabel):

    def wheelEvent(self, event):
        print(event.pixelDelta())

app = QtWidgets.QApplication([])
w = Q()
w.show()
app.exec_()

scrolling prints 'PyQt5.QtCore.QPoint()' without coordinates. What can I do?

like image 649
Dariush Avatar asked Nov 05 '16 21:11

Dariush


1 Answers

From the Qt5 docs for QWheelEvent:

There are two ways to read the wheel event delta: angleDelta() returns the delta in wheel degrees. This value is always provided. pixelDelta() returns the delta in screen pixels and is available on platforms that have high-resolution trackpads, such as OS X.

There is no pixelData in Qt4. It only has delta, and the equivalent Qt5 method to that is angleDelta.

like image 61
ekhumoro Avatar answered Sep 20 '22 05:09

ekhumoro