'bug of mouse event in the function mouseReleaseEvent() of PyQt5?
code first:
class MyWidget(QMainWindow)
def __init__(self):
super(MyWidget, self).__init__()
self.setMinimumSize(900, 500)
self.setMouseTracking(True)
def mousePressEvent(self, e):
if e.buttons() == Qt.LeftButton:
print('left pressed')
elif e.buttons() == Qt.RightButton:
print('right pressed')
else:
print('other button pressed')
def mouseReleaseEvent(self, e):
if e.buttons() == Qt.LeftButton:
print('left up')
elif e.buttons() == Qt.RightButton:
print('right up')
else:
print('other up')
just press the LEFT button, it outputs 'left pressed', but when release the LEFT button, it outputs 'other up', instead of 'left up'!!
it happens to the RIGHT button in the same way.
Solution 1:[1]
Just use e.button() instead of e.buttons()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohammad |
