我有一个使用QGraphicsView的pyside2 GUI。
我使用setDragMode(QGraphicsView.ScrollHandDrag)使视图可拖动,但是我使用mouseReleaseEvent上的viewport()。setCursor(Qt.ArrowCursor)覆盖了光标,以避免不断地张开而不是正常的箭头光标。 此处说明:Changing the cursor in a QGraphicsView(在c ++中)
在GUI中,还有一个带有QLabel的QGraphicsProxyWidget。当鼠标放在ProxyWidget上时,viewport()。setCursor(Qt.ArrowCursor)不起作用(调用了moseReleaseEvent,所以我知道调用了setCursor),当鼠标离开ProxyWidget时,打开了手光标显示,而不是箭头光标。
将鼠标放置在QGraphicsView的所有其他位置后,一切将按预期工作。
有人知道为什么将鼠标放在proxyWidget上时setCursor的行为会有所不同吗?
在QGraphicsView中:
def mouseReleaseEvent(self, event):
QGraphicsView.mouseReleaseEvent(self, event)
self.viewport().setCursor(Qt.ArrowCursor)
def infoBoxShow(self, edge, mouse_pos):
if self.info_box is None:
self.info_box = VardeInfoBox_v2.InfoBox()
self.info_box.corresponding_edge = edge
self.info_box.setPos(mouse_pos)
self.info_box.setInfoText(edge)
self.main_scene.addItem(self.info_box)
InfoBox(如您所见,我尝试设置一些标志但未成功):
class InfoBox(QGraphicsItem):
Type = QGraphicsItem.UserType + 1
def __init__(self):
QGraphicsItem.__init__(self)
self.setFlag(QGraphicsItem.hover)
self.setZValue(4)
proxy = QGraphicsProxyWidget(self)
widget = QLabel("TEST!")
widget.setAttribute(Qt.WA_TransparentForMouseEvents)
widget.setWindowModality(Qt.NonModal)
proxy.setWidget(widget)
self.corresponding_edge = None