PyQt/PySide QSpinBox flickering issue

蹲街弑〆低调 提交于 2019-12-13 01:26:02

问题


I have added a QSpinBox to a QGraphicsScene using a QGraphicsProxyWidget. Each time I hover over the QSpinBox, it flickers with a black band overlaid on the spinbox controls. I have attached a screenshot and the code below. Am I doing something wrong? Is there a way to avoid this? Pyside 1.1.2, Python 2.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_()

EDIT

Apparently there is a bug report filed here: Bugreport. I had to finally add the QSpinBox to a regular QWidget and not under QGraphicsView.


回答1:


Why do you put the spinbox in a QGraphicsScene? This seems rather odd. If you don't have some mysterious reason for that but just want a functional, nonflashing UI element, try making your testWidget a QDialog instead of a 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/pyqt-pyside-qspinbox-flickering-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!