Domanda

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.

QSpinBox flickering on hover

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.

È stato utile?

Soluzione

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_()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top