c++qtbackgroundqlineeditpalette

Qt Set Background Color of QLineEdit


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?


Solution

  • Works fine for me:

    QLineEdit *le = new QLineEdit();
    le->setStyleSheet("QLineEdit { background: rgb(0, 255, 255); selection-background-color: rgb(233, 99, 0); }");