[PyKDE] PyQt4: setPaletteBackgroundColor

Gerard Vermeulen gerard.vermeulen at grenoble.cnrs.fr
Wed Feb 8 19:08:21 GMT 2006


Please, read my mail again.  You are trying to do something which you
cannot do without a cast in C++, because QWidget::palette() returns
'const QPalette&'.  Python does not know about constness, and therefore
PyQt hands you a rope to hang yourself.

The road to independent palettes reads:

    palette = QPalette()
    setColorRoles(palette)
    self.setPalette(palette)
    palette = QPalette()
    setOtherColorRoles(palette)
    self.parentWidget().setPalette(palette)

Gerard

On Wed, 8 Feb 2006 09:48:16 -0900
Patrick Stinson <patrickkidd at gmail.com> wrote:

> If I change one of the to a QWidget (or QFrame) it doesn't work. Maybe we
> are (or I am) missing a fundamental aspect to this 'role' concept.
> 
>         self.w2 = QFrame(self)
>         self.w2.setFixedSize(100, 200)
>         self.w2.setFrameStyle(QFrame.WinPanel)
> 
> 
> 
> On 2/8/06, V. Armando Sole <sole at esrf.fr> wrote:
> >
> > At 08:26 08/02/2006 -0900, Patrick Stinson wrote:
> > >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
> >
> > Funny this example works as expected:
> >
> > from PyQt4.QtCore import *
> > from PyQt4.QtGui import *
> >
> > class AllGreen(QWidget):
> >      def __init__(self):
> >          QWidget.__init__(self)
> >          layout = QVBoxLayout(self)
> >
> >          self.w1 = QLineEdit(self)
> >          self.w2 = QLineEdit(self)
> >          self.w3 = QLineEdit(self)
> >
> >          palette = self.palette()
> >          role = self.backgroundRole()
> >          palette.setColor(role, QColor('green'))
> >          self.setPalette(palette)
> >
> >          palette1 = self.w1.palette()
> >          role = self.w1.backgroundRole()
> >          palette1.setColor(role, QColor('red'))
> >          self.w1.setPalette(palette1)
> >
> >          palette2 = self.w2.palette()
> >          role = self.w2.backgroundRole()
> >          palette2.setColor(role, QColor('yellow'))
> >          self.w2.setPalette(palette2)
> >
> >          palette3 = self.w3.palette()
> >          role = self.w3.backgroundRole()
> >          palette3.setColor(role, QColor('red'))
> >          self.w3.setPalette(palette3)
> >          layout.addWidget(self.w1)
> >          layout.addWidget(self.w2)
> >          layout.addWidget(self.w3)
> >
> > def testWidget():
> >      import sys
> >      a = QApplication(sys.argv)
> >      QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))
> >
> >      w = AllGreen()
> >      w.show()
> >      a.exec_()
> >
> > if __name__ == "__main__":
> >      testWidget()
> >
> > ************************************************************
> > 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/
> 




More information about the PyQt mailing list