简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM