[PySide] QTextEdit.setPalette() only works once [SOLVED]

Mark Summerfield mark at qtrac.eu
Wed Jun 18 14:32:19 CEST 2014


Hi,

This isn't a bug and here's the solution.

Call 

    QTextEdit.setAttribute(Qt.WA_TranslucentBackground)

once when the text edit is created, 

and then get and set the QTextEdit.viewport()'s palette.

(I've closed the bug report.)

On Wed, 18 Jun 2014 11:48:54 +0100
Mark Summerfield <mark at qtrac.eu> wrote:
> 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
        "Programming in Python 3" - ISBN 0321680561
            http://www.qtrac.eu/py3book.html



More information about the PySide mailing list