I new it! that worked for me<br><br><div><span class="gmail_quote">On 2/8/06, <b class="gmail_sendername">V. Armando Sole</b> <<a href="mailto:sole@esrf.fr">sole@esrf.fr</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Gerard,<br><br>At 20:08 08/02/2006 +0100, Gerard Vermeulen wrote:<br>>Please, read my mail again. You are trying to do something which you<br>>cannot do without a cast in C++, because QWidget::palette() returns<br>
>'const QPalette&'. Python does not know about constness, and therefore<br>>PyQt hands you a rope to hang yourself.<br>><br>>The road to independent palettes reads:<br>><br>> palette = QPalette()
<br>> setColorRoles(palette)<br>> self.setPalette(palette)<br>> palette = QPalette()<br>> setOtherColorRoles(palette)<br>> self.parentWidget().setPalette(palette)<br><br>As pointed out by "David Boddie" <
<a href="mailto:david@boddie.org.uk">david@boddie.org.uk</a>> :<br><br>[begin quote]<br><br>You can make the child widget visible by adding the following<br>line:<br><br> self.w.setAutoFillBackground(True)<br><br>
Contents propagation is enabled by default in Qt 4.1.0. For custom<br>widgets where you reimplement QWidget's paintEvent(), you can do<br>various things to allow effects like partial transparency for child<br>widgets while still adding your own colour scheme. However, a plain
<br>QWidget has to draw itself, so this seems like the quickest way to<br>get what you want.<br><br>David<br>[end quote]<br><br>The missing call setAutoFillBackground(True) was the critical thing.<br><br>The code below works as intended.
<br><br><br>from PyQt4.QtCore import *<br>from PyQt4.QtGui import *<br><br>class AllGreen(QWidget):<br> def __init__(self):<br> QWidget.__init__(self)<br> layout = QVBoxLayout(self)<br><br> self.w1
= QWidget(self)<br> self.w1.setFixedSize(100, 100)<br> self.w2 = QWidget(self)<br> self.w2.setFixedSize(100, 100)<br> self.w3 = QWidget(self)<br> self.w3.setFixedSize(100, 100)<br>
<br> palette = self.palette()<br> role = self.backgroundRole()<br> palette.setColor(role, QColor('green'))<br> self.setPalette(palette)<br><br> palette = self.w1.palette()<br> role =
self.w1.backgroundRole()<br> palette.setColor(role, QColor('red'))<br> self.w1.setPalette(palette)<br><br> palette = self.w2.palette()<br> role = self.w2.backgroundRole()<br> palette.setColor
(role, QColor('yellow'))<br> self.w2.setPalette(palette)<br><br> palette = self.w3.palette()<br> role = self.w3.backgroundRole()<br> palette.setColor(role, QColor('red'))<br> self.w3.setPalette
(palette)<br><br> layout.addWidget(self.w1)<br> layout.addWidget(self.w2)<br> layout.addWidget(self.w3)<br><br>def testWidget():<br> import sys<br> a = QApplication(sys.argv)<br> QObject.connect
(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))<br><br> w = AllGreen()<br> w.w1.setAutoFillBackground(True)<br> w.w2.setAutoFillBackground(True)<br> w.w3.setAutoFillBackground(True)<br>
w.show()<br><br> a.exec_()<br><br>if __name__ == "__main__":<br> testWidget()<br><br><br>Regards,<br><br>Armando<br><br>_______________________________________________<br>PyKDE mailing list <a href="mailto:PyKDE@mats.imk.fraunhofer.de">
PyKDE@mats.imk.fraunhofer.de</a><br><a href="http://mats.imk.fraunhofer.de/mailman/listinfo/pykde">http://mats.imk.fraunhofer.de/mailman/listinfo/pykde</a><br></blockquote></div><br><br clear="all"><br>-- <br>Patrick Kidd Stinson
<br><a href="http://pkaudio.sourceforge.net/">http://pkaudio.sourceforge.net/</a><br><a href="http://pksampler.sourceforge.net/">http://pksampler.sourceforge.net/</a>