[PySide] QTextEdit.setPalette() only works once

Mark Summerfield mark at qtrac.eu
Wed Jun 18 12:48:54 CEST 2014


Hi,

I have a QLineEdit (self.lineEdit) and a QTextEdit (self.textEdit) and
after creating them I call this custom method:

    def changeBackground(self, bg):
        palette = self.lineEdit.palette()
        palette.setBrush(QPalette.Base, QBrush(bg))
        self.lineEdit.setPalette(palette)
        
        palette = self.textEdit.palette()
        palette.setBrush(QPalette.Base, QBrush(bg))
        self.textEdit.setPalette(palette)

The bg is either a QColor or a QPixmap.

The first time I call this it works fine.

But the second and subsequent times I call it, it works correctly for
the QLineEdit, but has no effect on the QTextEdit.

I'm using:
Windows 7 - Python 3.3 - PySide 1.2.2 - Qt 4.8.5
Linux - Python 3.2 - PySide 1.1.1 - Qt 4.8.2

I've reported it as a Qt bug:
https://bugreports.qt-project.org/browse/QTBUG-39727

but was wondering if anyone can suggest a workaround?

Thanks.

PS autoFillBackground has no effect either way.
-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    Python and PyQt/PySide - training and consultancy
        "Python in Practice" - ISBN 978-0321905635
            http://www.qtrac.eu/pipbook.html



More information about the PySide mailing list