[SOLVED]Stylesheet - changing background color when text is entered in QLineEdit
-
Hi,
in my application i want to highlight mandatory fields when they are empty.
at the moment i'm doing it like this:
@
MainWindow w;
w.setStyleSheet("*[mandatoryField="true"][text=""] { background-color: yellow }");
@
@
//leInput is a QLineEdit
ui->leInput->setProperty("mandatoryField",true);
@This hightlights all mandatory fields, which are empty, but when the user enters a text in the field i would like to set the background-color back to normal.
Is it even possible for stylesheets to detect when the text changes?
-
you will have to do the check by yourself.
As soon as the user changes the text you need to do something like this:
@
if( ui->leInput->property("mandatoryField").toBool() )
{
ui->leInput->setProperty("mandatoryField",false);
ui->leInput->style()->polish(ui->leInput);
}
@ -
Check this "doc note":http://qt-project.org/doc/qt-5.0/qtwidgets/stylesheet-syntax.html#note-238