本文介绍了PyQt/PySide QSpinBox 闪烁问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 QGraphicsProxyWidget 添加了一个 QSpinBox 到 QGraphicsScene.每次我将鼠标悬停在 QSpinBox 上时,它都会闪烁,并在旋转框控件上覆盖一条黑色带.我附上了屏幕截图和下面的代码.难道我做错了什么?有没有办法避免这种情况?Pyside 1.1.2、Python 2.7、Windows7.

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_()

编辑

显然这里有一个错误报告:错误报告.我最终不得不将 QSpinBox 添加到常规的 QWidget 而不是在 QGraphicsView 下.

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.

推荐答案

你为什么把 spinbox 放在 QGraphicsScene 中?这似乎很奇怪.如果您对此没有什么神秘的原因而只是想要一个功能性的、非闪烁的 UI 元素,请尝试将您的 testWidget 设为 QDialog 而不是 QGraphicsView.

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_()

这篇关于PyQt/PySide QSpinBox 闪烁问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 19:51