Mailing List Archive

How to set text color using pyKDE 0.8?
I'm using pyKDE 0.8 binding for python.
I made a QLabel on the main widget. Now I'd like to change the color of the
text inside this QLabel.
I managed to change the backgroundcolor and the font. But I can't find any
info on how to change the color of the text, or the foregroundcolor.


/Peter Torstenson
Rio de Janeiro
How to set text color using pyKDE 0.8? [ In reply to ]
["Peter Torstenson"]
> I'm using pyKDE 0.8 binding for python.
> I made a QLabel on the main widget. Now I'd like to change the color of the
> text inside this QLabel.
> I managed to change the backgroundcolor and the font. But I can't find any
> info on how to change the color of the text, or the foregroundcolor.

I've just done some poking around... Qt 2.0 looks like it has really good
support for color control (presumably as part of the introduction of styles),
but of course we need pyKDE 0.9 for that...

I even tried supplying a QPainter through drawContents, but of course a
setBrush()'ed QColor gets nuked when the drawContents does a begin()...

A friend says he did it once, but he can't remember offhand how...


Richard
How to set text color using pyKDE 0.8? [ In reply to ]
Peter Torstenson <p.t@iname.com> wrote:
> I'm using pyKDE 0.8 binding for python.
> I made a QLabel on the main widget. Now I'd like to change the color of the
> text inside this QLabel.
> I managed to change the backgroundcolor and the font. But I can't find any
> info on how to change the color of the text, or the foregroundcolor.
This is a little bit tricky. Every widget has a palette() function which
returns a QPalette. This palette consists of three color-groups which can
be accessed through normal(), disabled() and disabled() and can be changed
trought its corresponding set-functions (setNormal(), ...). According to
the state of the widget one of these color-groups is shown. You can
find more about setting up color-groups in the QT docs (e.g qcolorgroup.html).

Hope that helps
Henning



----------------------------
#!/usr/bin/python

from kde import *

import sys
app = QApplication(sys.argv)
label = QLabel("Hello world!")

pal = label.palette()
pal.setNormal(QColorGroup(red, green, blue, black, gray, yellow, white))
label.setPalette(QPalette(pal))

label.show()
app.setMainWidget(label)
app.exec_loop()
----------------------------