
我正在创建一个节点图,我希望能够单击场景中的空白区域并拖动鼠标中键进行导航,而无需取消选择场景中当前选择的项目。有什么建议么?如何在不阻止鼠标中键单击场景中的情况下停止在QGraphicsScene中取消选择项目?
我可以防止在视图的mousePressEvent中进行中间单击并获得正确的行为,但是随后我不再具有对场景中的项目进行操作的mouse click事件。单击场景中的项目时,我不介意单击选择,但是如果单击场景中的空白区域,则不希望更改选择。

这不包括我正在寻找的更复杂的行为:PyQt。如何在鼠标右键单击时阻止清除选择?
我没有尝试使用eventFilter,因为我认为问题将是相同的

我使用Fyw的PyQt / PySide。
在我启动自己的解决方案之前,我想我会在这里发布正确的解决方案或至少其他解决方案的想法。

一些解决方法:
任何反馈都会很棒!

[编辑:]这是我的python版本的答案。代码测试。在我的QGraphicsScene派生类中:
def mousePressEvent(self, event):
# Prevent the QGraphicsScene default behavior to deselect-all when clicking on
# empty space by blocking the event in this circumstance.
item_under_the_mouse = self.itemAt(event.scenePos())
if event.button() == QtCore.Qt.MidButton and not item_under_the_mouse:
event.accept()
else:
super(GraphScene, self).mousePressEvent(event)
来源
2017-03-06Rafe
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/bofangqi/article-335022-1.html
等我强大了第一要灭的就是美帝