[PyQt] coloring a QDialog

Phil Thompson phil at riverbankcomputing.com
Wed Apr 8 22:37:37 BST 2009


On Wed, 08 Apr 2009 10:26:18 +0200, TP <paratribulations at free.fr> wrote:
> Hi everybody,
> 
> To color a QDialog (for example), I can do:
> 
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> import sys
> app = QApplication( sys.argv )
> dialog = QDialog( )
> dialog.palette().background().setColor(Qt.blue) # @
> dialog.show()
> app.exec_()
> 
> But if I replace the line "@" by:
> 
> dialog.setForegroundRole( QPalette().Dark )
> 
> it seems it does not work: the color is the same with and without this
> line.
> 
> What is the problem?

You can't update a palette in-situ, you need to call setPalette() with the
modified palette.

Phil


More information about the PyQt mailing list