我已经使用QGraphicsProxyWidget向QGraphicsScene添加了一个QSpinBox。每次我将鼠标悬停在QSpinBox上时,它都会闪烁,并在spinbox控件上覆盖一条黑色带子。我已经附上了截图和下面的代码。我做错了什么吗?有没有办法避免这种情况?Pyside 1.1.2,Python2.7,Windows7。

class testWidget(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)
floorSpinBox = QSpinBox()
floorSpinBox.setGeometry(0,0,50,25)
proxyWidget = QGraphicsProxyWidget()
proxyWidget.setWidget(floorSpinBox)
scene = QGraphicsScene(self)
scene.addItem(proxyWidget)
self.setScene(scene)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = testWidget()
widget.show()
app.exec_()编辑
显然,这里有一个bug报告:Bugreport。我最终不得不将QSpinBox添加到常规的QWidget中,而不是添加到QGraphicsView下。
发布于 2012-10-05 06:15:12
为什么你要把spinbox放在QGraphicsScene里?这看起来很奇怪。如果您没有什么神秘的原因,而只是想要一个功能强大、不闪烁的UI元素,请尝试将您的testWidget设置为QDialog而不是QGraphicsView。
from PyQt4.QtGui import QDialog, QSpinBox,QApplication
import sys
class testWidget(QDialog):
def __init__(self):
QDialog.__init__(self)
self.setGeometry(200,200,200,100)
floorSpinBox = QSpinBox(self)
floorSpinBox.setGeometry(75,40,50,25)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = testWidget()
widget.show()
app.exec_()https://stackoverflow.com/questions/12736688
复制相似问题