[PyKDE] changing background color of QTextEdit/QLineEdit

Doug Bell dougb at bellz.org
Mon Jan 15 13:47:51 GMT 2007


Steven James Samuel Stapleton wrote:
> I have severa QTextEdits and QLineEdits in my application, and I want to 
> make them more friendly for the user.
> 
> (1) I would like to slightly alter the color of the focused edit object 
> (it's very helpful for visually impared users such as myself).
> (2) I want to make bad input sections red.
> 
> To do this, I need to know how to (a) get the background color used and (b) 
> set the background color used.
> 
> Any suggestions?

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.




More information about the PyQt mailing list