我使用QGraphicsView
来创建一种圆圈编辑器,其中包含有连接器的元素。应该可以用电线连接这些连接器。
但是,我有一个问题,当我从一个连接器拖到另一个连接器时,Qt抓取鼠标,其他连接器停止接收hoverEnterEvent
。顺便说一句,在悬停连接器上调整大小,因此更容易击中它们。
再一次,是否可以在拖动时抓住鼠标?
我已经使用Qt 4.5 for Windows。
根据要求,以下是一些消息来源: http://pastebin.com/m422b9495
答案 0 :(得分:0)
我认为您需要将interactive mode设置为false。
答案 1 :(得分:0)
在拖动操作期间更改鼠标悬停行为在某种程度上是很典型的。通常会响应鼠标移动的小部件在拖动过程中往往不会响应,除非它们可以接收相关的放置。因此,通常的悬停事件被抑制。 (检查窗口小部件是否接受某些放置是不够的,因为问题是窗口小部件是否可以接受该放置。)除了悬停事件之外,还尝试使用拖动的enter和离开事件来调整连接器的大小。
答案 2 :(得分:0)
您可以在源项目中使用mouseMoveEvent来检查光标何时在目标项目上。
例如:
def mouseMoveEvent(self, event):
item = self.scene().itemAt(event.scenePos(), self.scene().views([0].transform())
if isinstance(item, NodeConnectionGraphicItem):
if self.item_over_drag is None:
self.item_over_drag = item
item.highlighted_mouse_over = True
...
item.update()
elif self.item_over_drag is not None:
self.item_over_drag.highlighted_mouse_over = False
self.item_over_drag.update()
self.item_over_drag = None