Qt Set Background Color of QLineEdit

前端 未结 4 1179

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 th

4条回答
  •  伪装坚强ぢ
    2020-12-18 21:17

    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:

    QPalette palette = _ui->lnSearch->palette();
    palette.setColor(QPalette::Base, Qt::green);
    _ui->lnSearch->setPalette(palette);
    

    Thanks to: https://forum.qt.io/topic/64568/why-setting-background-color-of-qlineedit-has-no-effect

提交回复
热议问题