I am trying to create a demonstration app to show how to change font colors.
I can do it in QLabel and QTextEdit
I have found no way to change the foreground text color for a QLineEdit.
The only thing I've tried that does not throw an error is:
color = QColorDialog.getColor(defaultHost.textColor(), pWidget, 'Get Text Color')
myPalette.setColor(myPalette.WindowText, QColor(color))
But, the text color remains black...
Is it or is it not possible to do this?
I solved for font text and background
this is how I do it not using css
QLineEdit has a method initStyleOption and initStyleOption inherits QStyleOption, and then QStyleOption has a Method QPalette. Now you can take advatage of using QPalette methods.
you can visit this link for reference http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html
You can do it by setting the object's style sheet:
Below is a code snippet that took me two days of trial and error to figure out. I hope it helps other newbies like myself. My comments in the code should help, too.
This snippet shows:
QColor
from aQColorDialog
into a string HEX format for use with a stylesheet; andQColorDialog
when the widget doesn't use a palette element of the type you need.In my case I am using
defaultHost = led_dem.textEdit
whereled_dem
is my form andtextEdit
is atextEdit
on the form.Also,
pWidget
is the complete widget definition includingform
andinstance
.