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> <<a href="mailto:gerard.vermeulen@grenoble.cnrs.fr">
gerard.vermeulen@grenoble.cnrs.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;">On Tue, 7 Feb 2006 14:11:46 -0900<br>
Patrick Stinson <<a href="mailto:patrickkidd@gmail.com">patrickkidd@gmail.com</a>> wrote:<br><br>> I relaize that this is a question for qt-interest, but I'm getting a slow<br>> response.<br>><br>> What is the preferred method for setting the background color of a widget in
<br>> qt4? I'm using palette().setColor(QPalette.Window, mycolor)), but this<br>> setting for child widgets seems to be overriden by the color you set the<br>> parent widget with. Are you supposed to draw a rect in paintEvent()? The
<br>> QWidget docs don't seem to say much.<br>><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> def __colorTheme(self, base):<br> background = base.dark(150)<br> foreground = base.dark(200)<br>
<br> mid = base.dark(110)<br> dark = base.dark(170)<br> light = base.light(170)<br> text = foreground.light(800)<br><br> palette = QtGui.QPalette()<br> for colorGroup in colorGroupList:
<br> palette.setColor(colorGroup, QtGui.QPalette.Base, base)<br> palette.setColor(colorGroup,
QtGui.QPalette.Background, background)<br> palette.setColor(colorGroup, QtGui.QPalette.Mid, mid)<br> palette.setColor(colorGroup,
QtGui.QPalette.Light, light)<br> palette.setColor(colorGroup, QtGui.QPalette.Dark, dark)<br> palette.setColor(colorGroup, QtGui.QPalette.Text, text)<br> palette.setColor(colorGroup,
QtGui.QPalette.Foreground, foreground)<br><br> return palette<br><br> # __colorTheme()<br><br>and elsewhere __colorTheme() is used as:<br><br> def __init__(self, *args):<br> QtGui.QFrame.__init__(self, *args)
<br> self.setPalette(<br> 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 <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>