I see. I read in the qt-4.1 docs that QPalette.Background is deprecated in favor of QPalette.Window. Comments?<br><br><div><span class="gmail_quote">On 2/7/06, <b class="gmail_sendername">Gerard Vermeulen</b> &lt;<a href="mailto:gerard.vermeulen@grenoble.cnrs.fr">
gerard.vermeulen@grenoble.cnrs.fr</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Tue, 7 Feb 2006 14:11:46 -0900<br>
Patrick Stinson &lt;<a href="mailto:patrickkidd@gmail.com">patrickkidd@gmail.com</a>&gt; wrote:<br><br>&gt; I relaize that this is a question for qt-interest, but I'm getting a slow<br>&gt; response.<br>&gt;<br>&gt; What is the preferred method for setting the background color of a widget in
<br>&gt; qt4? I'm using palette().setColor(QPalette.Window, mycolor)), but this<br>&gt; setting for child widgets seems to be overriden by the color you set the<br>&gt; parent widget with. Are you supposed to draw a rect in paintEvent()? The
<br>&gt; QWidget docs don't seem to say much.<br>&gt;<br><br>It is the C++ reference returned by Qt's palette() which bites you. You<br>change the palette, but it is still shared with the other widgets in the<br>widget tree that your widget is part of.
<br><br>A work-around is to explicitly create a palette (from a not yet released<br>PyQwt-5 example):<br><br>&nbsp;&nbsp;&nbsp;&nbsp;def __colorTheme(self, base):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background = base.dark(150)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreground = base.dark(200)<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mid = base.dark(110)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dark = base.dark(170)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;light = base.light(170)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text = foreground.light(800)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette = QtGui.QPalette()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for colorGroup in colorGroupList:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup, QtGui.QPalette.Base, base)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup,
QtGui.QPalette.Background, background)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup, QtGui.QPalette.Mid, mid)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup,
QtGui.QPalette.Light, light)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup, QtGui.QPalette.Dark, dark)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup, QtGui.QPalette.Text, text)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;palette.setColor(colorGroup,
QtGui.QPalette.Foreground, foreground)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return palette<br><br>&nbsp;&nbsp;&nbsp;&nbsp;# __colorTheme()<br><br>and elsewhere __colorTheme() is used as:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, *args):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QtGui.QFrame.__init__(self, *args)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.setPalette(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.__colorTheme(QtGui.QColor(QtCore.Qt.darkGray).dark(150)))<br><br>This is a nasty pitfall, because the references returned by Qt are quite often<br>shared and Python programmers have to be aware of this.
<br><br>Gerard<br><br>_______________________________________________<br>PyKDE mailing list&nbsp;&nbsp;&nbsp;&nbsp;<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>