小编use*_*951的帖子

更改 QGraphicsScene 中的多选绑定键

QGraphicsScene在 PyQT 中进行子类化,并希望使用Shift键(修饰符)来代替键来进行多选项目control

我可以通过子类化它并制作自己的 来做到这一点mousePressedEvent,但是当我这样做时,当我开始拖动场景中的graphicsItem时,它们会表现得很奇怪。

我需要的只是将control键更改shift为多选键。如果有人可以提供帮助,我将不胜感激。

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class GraphicsScene(QGraphicsScene):
    def __init__(self, parent=None, ns=""):
        super(GraphicsScene, self).__init__(parent)
        self.parent = parent
        self.prevItem = []
        self.ns = ns
        self.setBackgroundBrush(QBrush(QColor(50,50,50) , Qt.SolidPattern))


    def mouseReleaseEvent(self, event):
        if event.button() == 2: #Right mouse click
            #Set previous selections selected
            for item in self.prevItem:
                item.setSelected(1)

            item = self.itemAt(event.lastScenePos ().x(), event.lastScenePos ().y())
            if item:
                item.setSelected(1)

        if event.button() == 1: # Left …
Run Code Online (Sandbox Code Playgroud)

pyqt qgraphicsview qgraphicsscene

6
推荐指数
1
解决办法
1829
查看次数

标签 统计

pyqt ×1

qgraphicsscene ×1

qgraphicsview ×1