[PyKDE] PyQt4: setPaletteBackgroundColor

Patrick Stinson patrickkidd at gmail.com
Wed Feb 8 17:26:28 GMT 2006


Yeah, I"m getting the same problem. If you set the role color for the child
widget, and set the role color for the parent widget, the child widget just
gets the color for the parent widget. This means that you can't give child
widgets their own color. For example, the following code shows no red

class AllGreen(QWidget):
    def __init__(self):
        QWidget.__init__(self)

        self.w = QWidget(self)
        self.w.setFixedSize(100, 100)

        palette = self.w.palette()
        role = self.w.backgroundRole()
        palette.setColor(role, QColor('red'))
        self.w.setPalette(palette)

        palette = self.palette()
        role = self.backgroundRole()
        palette.setColor(role, QColor('green'))
        self.setPalette(palette)



On 2/7/06, V. Armando Sole <sole at esrf.fr> wrote:
>
> Hi,
>
> At 14:11 07/02/2006 -0900, you wrote:
> >I relaize that this is a question for qt-interest, but I'm getting a slow
> >response.
> >
> >What is the preferred method for setting the background color of a widget
> >in qt4? I'm using palette().setColor(QPalette.Window, mycolor)), but this
> >setting for child widgets seems to be overriden by the color you set the
> >parent widget with. Are you supposed to draw a rect in paintEvent()? The
> >QWidget docs don't seem to say much.
>
> I am using this for changing the background color in QLineEdit widgets and
> so on (self is a QLineEdit derived class). You can give a try:
>
>      def setPaletteBackgroundColor(self, color):
>              palette = self.palette()
>              role = self.backgroundRole()
>              palette.setColor(role,color)
>              self.setPalette(palette)
>
> It is almost what you are doing. Could it be you are not giving the
> appropriate role?
>
> Regards,
>
> Armando
> ************************************************************
> V. A. Solé
> ESRF - BLISS Group PHONE: +33 (0)4 76 88 25 84
> BP 220                     FAX:       +33 (0)4 76 88 25 42
> 38043 - Grenoble Cedex
> France
> ************************************************************
>
>


--
Patrick Kidd Stinson
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060208/61dd0611/attachment.html


More information about the PyQt mailing list