doityth777
doityth777

Reputation: 93

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.

Upvotes: 0

Views: 108

Answers (1)

Mohammad
Mohammad

Reputation: 77

Just use e.button() instead of e.buttons()

Upvotes: 1

Related Questions