b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

意外:如何在不阻止鼠标从场景中的项目的情况下停止在QGraphicsScene中取消选择项目

电脑杂谈  发布时间:2020-11-21 23:06:29  来源:网络整理

qgraphicsscene设置鼠标状态_qgraphicsscene设置鼠标状态

我正在创建一个节点图,我希望能够单击场景中的空白区域并拖动鼠标中键进行导航,而无需取消选择场景中当前选择的项目。有什么建议么?如何在不阻止鼠标中键单击场景中的情况下停止在QGraphicsScene中取消选择项目?

我可以防止在视图的mousePressEvent中进行中间单击并获得正确的行为,但是随后我不再具有对场景中的项目进行操作的mouse click事件。单击场景中的项目时,我不介意单击选择,但是如果单击场景中的空白区域,则不希望更改选择。

qgraphicsscene设置鼠标状态_qgraphicsscene设置鼠标状态

这不包括我正在寻找的更复杂的行为:PyQt。如何在鼠标右键单击时阻止清除选择?

我没有尝试使用eventFilter,因为我认为问题将是相同的

qgraphicsscene设置鼠标状态_qgraphicsscene设置鼠标状态

我使用Fyw的PyQt / PySide。

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

qgraphicsscene设置鼠标状态_qgraphicsscene设置鼠标状态

一些解决方法:

任何反馈都会很棒!

qgraphicsscene设置鼠标状态_qgraphicsscene设置鼠标状态

[编辑:]这是我的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

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...