我遇到了一个非常奇怪的问题。每当 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
子类需要重新实现 boundingRect
和 paint
功能。
关于python - Pyside 程序响应复选框单击而锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12183744/