Important: Please read the Qt Code of Conduct -

How to set background color of my QTextEdit?

  • Hi,

    I have QTextEdit object. I would like to change his background color to color, which my MainWindow has ( it is gray ). How can I do that?

    I tried like this:

        QPalette palette2 = textEdit->palette();

  • @qwe3
    I believe if you want to do it this way you have to set autoFillBackground.

    You don't have to do that if you use stylesheet instead.

  • Lifetime Qt Champion

    It has to be the right role. QWidget::backgroundRole() is not used it seems.


        QPalette p = ui->textEdit->palette();
        p.setColor(QPalette::Base, Qt::red); // BG
        p.setColor(QPalette::Text, Qt::white); // (plain) TEXT

    alt text

Log in to reply