PyQt.如何在鼠标右键单击时阻止清除选择?
我有一个 QGraphicsScene 和许多可选项目.但是当我单击鼠标右键时 - 取消选择所有对象.我想显示菜单并编辑选定的对象,但在鼠标右键单击时可以随时自动取消选择...
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?
Daniele Pantaleone 的回答给了我一个思路,我修改了mousePressEvent()
的函数,立马得到了想要的效果我>
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)