Search code examples
pythonpyqtqgraphicsscene

PyQt. How to block clear selection on mouse right click?


I have a QGraphicsScene and many selectable items. But when I click the right mouse button - deselects all objects. I want show menu and edit selected objects but have automatic deselect any time when right click at mouse...

Perhaps the problem is that I have included an rubber selection. selection of objects in the end is how the right and the left mouse button when I pull the frame and therefore is reset at single time you press the right button...

How to leave objects highlighted when you click on the right mouse button? Or it may be necessary to disable the rubber selection of the right button?


Solution

  • Daniele Pantaleone answer gave me an idea and I have modified the function of mousePressEvent() and immediately got the desired effect me

    def mousePressEvent(self, event):
        if event.button() == Qt.MidButton:
            self.__prevMousePos = event.pos()
        elif event.button() == Qt.RightButton: # <--- add this 
            print('right')
        else:
            super(MyView, self).mousePressEvent(event)