pyqt / python-qt5

Unofficial PyQt5 via PyPI for Python 2.7 64-bit on Windows
GNU General Public License v3.0
280 stars 77 forks source link

Problem with mouse wheel event with Alt key modifier (Alt held down) #73

Closed megies closed 1 year ago

megies commented 1 year ago

Problem description

I have a PyQt GUI application that does some zooming around in various fashions based on mouse wheel events in combination with different keyboard modifiers influencing behavior.

At some point zooming with "Alt" key modifier (i.e. key held down while scrolling wheel) stopped working (could have even been back on PyQt4 but it definitely worked at some point). I did not have time to investigate at that point but came back to the issue now.

It seems there is a bug whenever "Alt" key is held down the angleDelta().y() is 0 instead of the usual 120 or -120 for common mice for one scroll tick up/down. This means wheel events can not be used with Alt key held down, since they its core information (wheel direction).

If this is an upstream problem of Qt, please let me know how to best report it there, as I exclusively use Qt via PyQt.

To reproduce:

Expected outcome

When holding down Alt key, the reported angle on mouse wheel zoom should be the same as without modifiers or using other modifiers like shift etc. In this example it should be 120 like without alt key held down.

Code to reproduce

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.label = QLabel("scroll mouse wheel here")
        self.setCentralWidget(self.label)

    def wheelEvent(self, e):
        info = [
            "",
            "wheel event",
            "modifier: %d" % e.modifiers(),
            "angleDelta.y: %d" % e.angleDelta().y(),
            ]
        self.label.setText('\n'.join(info))

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()

Screenshots

1: wheel up, no key held

Screenshot from 2022-10-06 14-22-14

2: wheel up, shift key held

Screenshot from 2022-10-06 14-22-30

3: wheel up, alt key held

Screenshot from 2022-10-06 14-25-07

Version info

$ conda list qt
# Name                    Version                   Build  Channel
pyqt                      5.12.3          py310hff52083_8    conda-forge
pyqt-impl                 5.12.3          py310h1f8e252_8    conda-forge
pyqt5-sip                 4.19.18         py310h122e73d_8    conda-forge
pyqtchart                 5.12            py310hfcd6d55_8    conda-forge
pyqtwebengine             5.12.1          py310hfcd6d55_8    conda-forge
qt                        5.12.9               h1304e3e_6    conda-forge
megies commented 1 year ago

After wondering what happened to this ticket and coming back, I realized that this was likely reported in the wrong place, see #32

megies commented 1 year ago

For what it's worth, turns out this is intended (but not well documented) behavior. Alt key modifier simulates horizontal scrolling and the scrolling value can be found in angleDelta().x() instead in that case.

https://bugreports.qt.io/browse/QTBUG-78550