I'm trying to change the background color of the QLineEdit
and I can't figure it out at all.
I tried using stylesheets
originally like this
QLineEdit *le = new QLineEdit();
le->setStyleSheet("background:#000;");
but that didn't do anything. I tried using QPalette
like this
QPalette palette;
palette.setColor(QPalette::Base, Qt::black);
palette.setColor(QPalette::Background, Qt::black);
le.setPalette(palette);
but this didn't do anything either. I've been looking all day and can't find anything. am I doing something wrong or is there another way to do it?
SOLVED how to change the background color of QLineEdit Try this : QPalette *palette = new QPalette(); palette->setColor(QPalette::Base,Qt::gray); ui->lineEdit->setPalette(*palette); Out of curiosity if our QLineEdit is disabled it should have the look and feel of your OS (in my case = grey) to reflect that.
You can disable QLineEdit using method "setEnabled ( false )":http://qt-project.org/doc/qt-4.8/qwidget.html#enabled-prop which is inherited from QWidget.
You can set the background and text colors of line edit by setting the palette like :
QLineEdit *le = new QLineEdit();
QPalette palette;
palette.setColor(QPalette::Base,Qt::black);
palette.setColor(QPalette::Text,Qt::white);
le->setPalette(palette);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With