[PyQt] set qlineedit red, easy?? SOLVED

Mads Ipsen mpi at comxnet.dk
Thu Feb 5 12:45:40 GMT 2009


--------- Original Besked --------
Fra: Knapp <magick.crow at gmail.com>
Til: Frédéric <frederic.mantegazza at gbiloba.org>
Cc: pyqt at riverbankcomputing.com
Emne: Re: [PyQt] set qlineedit red, easy?? SOLVED
Dato: 05/02/09 13:11

> On Thu, Feb 5, 2009 at 12:50 PM, Frédéric
> &lt;frederic.mantegazza at gbiloba.org&gt; wrote:
> &gt;
> &gt; Le 5/2/2009, &quot;Knapp&quot; &lt;magick.crow at gmail.com&gt; a écrit:
> &gt;
> &gt;&gt;I have a qlineedit that I want to turn the background red when the
> &gt;&gt;input is bad but I can't seem to find how to do this. I would
think it
> &gt;&gt;would be easy but it does not seem to be. unless I missed
something.
> &gt;
> &gt; Using a stylesheet?
> &gt;
> &gt; css = &quot;&quot;&quot;QLineEdit {
> &gt;     background-color: red;
> &gt; }&quot;&quot;&quot;
> &gt; myWidget. setStyleSheet(css)
> &gt;
> &gt; I didn't test...
> &gt;
> &gt; http://doc.trolltech.com/4.4/stylesheet.html#overview
> &gt; http://doc.trolltech.com/4.4/qwidget.html#styleSheet-prop
> &gt;
http://doc.trolltech.com/4.4/stylesheet-examples.html#customizing-qlineedit
> &gt;
> &gt; --
> &gt;   Frédéric
> &gt;
> 
> Worked perfectly. I knew it had to be easy and I overlooked the answer!
> Thanks all.
> -- 
> Douglas E Knapp
> 
> Amazon Gift Cards; let them choose!!
>
http://www.amazon.com/gp/product/B001078FFE?ie=UTF8&amp;tag=seattlebujinkand&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B001078FFE
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 

You can also do:

line_edit = QLineEdit()
palette = QPalette()
palette.setColor(widget.backgroundRole(), QColor('red'))
line_edit.setPalette(palette)

for a more subtle effect, you might consider exchanging backgroundRole()
with foregroundRole().

Mads


More information about the PyQt mailing list