python - Pyside 程序响应复选框单击而锁定

标签 python qt4 pyside

我遇到了一个非常奇怪的问题。每当 QCheckBox 被选中时,它都会按预期调用drawall。然而,当drawall完成后,它完全挂起。我尝试在单击时直接调用drawall(版本2),但不幸的是结果是相同的。

scene = QGraphicsScene(0, 0, 500, 500)

class SurrogateBeat(QGraphicsItem):
    def __init__(self,beat,top):
        super(SurrogateBeat, self).__init__()
        print "Init"

class Test(QWidget):
    def __init__(self):
        self.drawAll = QCheckBox("Draw all frames on screen",self)
        self.drawAll.stateChanged.connect(self.onDrawAllClicked)

    def onDrawAllClicked(self):                #Version 1
        QTimer.singleShot(0, self.drawall)

    def onDrawAllClicked(self):                #Version 2 (neither work)
        self.drawall()

    def drawall(self):
        if self.drawAll.checkState() ==  Qt.CheckState.Checked: 
            self.surrogates=[]
            for b in range(0,len(self.item.beats)):
                print "Loop"
                surrogate = SurrogateBeat(b, self.item)
                scene.addItem(surrogate)
                self.surrogates.append(surrogate)
            scene.update()
            print "Update"

Loop 打印了 16 次,SurrogateBeat 的 init 打印出来,因此它正在被调用,但是在“Update”打印出来之后,程序被挂起。

最佳答案

QGraphicsItem是一个抽象基类。

至少,您的 SurrogateBeat 子类需要重新实现 boundingRectpaint功能。

关于python - Pyside 程序响应复选框单击而锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12183744/

相关文章:

Python - 多个迭代的排气图

python csv.read 在第二次迭代时失败

c++ - 在 ImageView Blackberry 10 中动态设置 imageSource

python-3.x - PySide2 和 pyinstaller gui 应用程序无法在某些 Windows 计算机上运行

python - 我想要一个 turtle 图形中的弹跳球在墙上,但它们停下来,它们徘徊并发送错误

c++ - QSplitter 在 QWidget 和 QTabWidget 之间变得无法区分

windows - QT QTcpServer telnet 取字符\r\n

python - QTableview指定标准搜索字段

python - 无法使用 'pyside-rcc' 编译 .qrc 文件

python - 如何读取 n 个变量中的 n 个文件,然后将这些变量添加到列表中?