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?
I had to use background-color from standard css like this:
I am using Qt 5.4
You can set the background and text colors of line edit by setting the palette like :
Your code is almost correct. Only QLine edit uses the Base color. So if you do not want to replace existing stylesheet which can contain borders padding and margin and you want to change background only, use QPalette:
Thanks to: https://forum.qt.io/topic/64568/why-setting-background-color-of-qlineedit-has-no-effect
Works fine for me: