How to check MouseButtonPress event in PyQt6?

One of the main changes that PyQt6 enums use python enums so you must use the enumeration name as an intermediary, in your case MouseButtonPress belongs to the Type enum and RightButton to MouseButtons so you must change it to:

def eventFilter(self, QObject, event):
    if event.type() == QEvent.Type.MouseButtonPress:
        if event.button() == Qt.MouseButtons.RightButton:
            print("Right button clicked")

    return True

Leave a Comment