1

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.

jSmith
  • 53
  • 8

1 Answers1

0

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_()
Junuxx
  • 14,011
  • 5
  • 41
  • 71
  • Well, this is part of a larger application where I am displaying a large number of graphic elements in the window. I need some user interaction with the `QSpinBox` to control the display of these elements. I have the central widget inside `QMainWindow` set to `QTabWidget` and each of the tabs is set to `QGraphicsView` and am now trying to add other elements onto one of the tabs. – jSmith Oct 04 '12 at 22:27
  • @JohnSmith: Does the problem go away if its being used in a normal widget? Qt Devs even suggest to avoid proxy widgets in QGraphics if you can help it. – jdi Oct 04 '12 at 22:35
  • @jdi: I am afraid not, the flickering still persists. Another post here though suggests proxywidgets might be the way to go, so I assumed it was the appropriate method to adopt. http://stackoverflow.com/q/2985374/1718027 – jSmith Oct 04 '12 at 22:46
  • 1
    @jSmith: I'm sure people would suggest them because they are indeed part of the framework, but when I watched a presentation from the devs about QGraphicsScene, they talked about how they were added purely for a convenience. They are slower and require extra work to be drawn, and he said to try and avoid them, using them only as a last resort. – jdi Oct 04 '12 at 22:55
  • 1
    @jSmith: The flicker did disappear for me after switching to a normal widget - in PyQt4.7 that is. I would put a layout in the `QTabWidget` containing both the `QGraphicsView` and the `QSpinBox`, so that the spinbox doesn't have to be inside the graphicsview. – Junuxx Oct 04 '12 at 22:56
  • @Junuxx: Thanks a lot.! That worked for me too. I had to change a bunch of things but layout under a normal widget worked clean. Also, I found this: [bug-link](https://bugreports.qt-project.org/browse/QTBUG-18167). So apparently this seems to be a bug.. – jSmith Oct 04 '12 at 23:46