[PyKDE] changing background color of QTextEdit/QLineEdit
Steven James Samuel Stapleton
stapleton at mps.ohio-state.edu
Wed Jan 17 00:15:02 GMT 2007
I fiddle with this and got it working for the most part, thanks for the
info.
However, I have found one thing where it doesn't work: QTextEdit objects
don't seem to follow the palette setup. I have the same code for the
TextEdits and the LineEdits (it's a "ui_good(self, ui_object)" and
"ui_bad(self, ui_object)" type function, where self is the container and
ui_object is the object to change color. The code looks pretty much like
what you have below. When a LineEdit is passed, it will change red with
ui_bad, and the light/pastel blue that is in the windows default palette (my
default text background) when I pass it to ui_good. When a TextEdit is
passed, there is no change.
I haven't tested it on my BSD machine yet (to see if it's a windows only
error).
Any idea on that one?
Thanks,
-Jim Stapleton
----- Original Message -----
From: "Doug Bell" <dougb at bellz.org>
To: "Steven James Samuel Stapleton" <stapleton at mps.ohio-state.edu>
Sent: Monday, January 15, 2007 9:46 AM
Subject: Re: [PyKDE] changing background color of QTextEdit/QLineEdit
>> >It's not difficult. Check the Qt documentation for the QWidget.palette
>> >property and for the QPalette class. The class lets you get
>> >(QPalette.color()) and set (QPalette.setColor()) the color for various
>> >color groups and color roles. The groups let you set colors for active
>> >(focused) and inactive states, and the roles for Text (foreground) and
>> >Base (background).
>> >
>> >Doug.
>>
>> So, that only effects the widget and not the whole app?
>
> Yes, as long as you use QWidget.setPalette() and not
> QApplication.setPalette(). Remember that your QLineEdit inherits from
> QWidget, so your code might look something like this:
>
> editor = QLineEdit()
> palette = editor.palette()
> palette.setColor(QPalette.Active, QPalette.Text, QColor(255, 0, 0))
> palette.setColor(QPalette.Active, QPalette.Base, QColor(50, 50, 50))
> editor.setPalette(palette)
>
> Doug.
>
More information about the PyQt
mailing list