[PyKDE] PyQt4: setPaletteBackgroundColor
Patrick Stinson
patrickkidd at gmail.com
Wed Mar 29 01:19:36 BST 2006
this is interestin because the palette still doesn't propogate to the
widgets' children.
"""
A common base class for all pk widgets.
"""
from PyQt4.QtGui import QFrame, QPalette
class PKWidget(QFrame):
""" Conveinience class """
def set_background(self, color):
palette = QPalette()
palette.setColor(QPalette.Window, color)
palette.setColor(QPalette.Background, color)
self.setPalette(palette)
On 2/7/06, Gerard Vermeulen <gerard.vermeulen at grenoble.cnrs.fr> wrote:
>
> On Tue, 7 Feb 2006 14:11:46 -0900
> Patrick Stinson <patrickkidd at gmail.com> 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.
> >
>
> It is the C++ reference returned by Qt's palette() which bites you. You
> change the palette, but it is still shared with the other widgets in the
> widget tree that your widget is part of.
>
> A work-around is to explicitly create a palette (from a not yet released
> PyQwt-5 example):
>
> def __colorTheme(self, base):
> background = base.dark(150)
> foreground = base.dark(200)
>
> mid = base.dark(110)
> dark = base.dark(170)
> light = base.light(170)
> text = foreground.light(800)
>
> palette = QtGui.QPalette()
> for colorGroup in colorGroupList:
> palette.setColor(colorGroup, QtGui.QPalette.Base, base)
> palette.setColor(colorGroup, QtGui.QPalette.Background,
> background)
> palette.setColor(colorGroup, QtGui.QPalette.Mid, mid)
> palette.setColor(colorGroup, QtGui.QPalette.Light, light)
> palette.setColor(colorGroup, QtGui.QPalette.Dark, dark)
> palette.setColor(colorGroup, QtGui.QPalette.Text, text)
> palette.setColor(colorGroup, QtGui.QPalette.Foreground,
> foreground)
>
> return palette
>
> # __colorTheme()
>
> and elsewhere __colorTheme() is used as:
>
> def __init__(self, *args):
> QtGui.QFrame.__init__(self, *args)
> self.setPalette(
> self.__colorTheme(QtGui.QColor(QtCore.Qt.darkGray).dark(150)))
>
> This is a nasty pitfall, because the references returned by Qt are quite
> often
> shared and Python programmers have to be aware of this.
>
> Gerard
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
>
--
Patrick Kidd Stinson
http://www.patrickkidd.com/
http://pkaudio.sourceforge.net/
http://pksampler.sourceforge.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20060329/2d59451c/attachment.html
More information about the PyQt
mailing list