I want the QtextEdit in my app to be green so I set the stylesheet to
background-color: rgb(109, 255, 99);
However this also change the background color of the scrollbars and even when I click mouse right button in the textedit the menu that is shown is also green and that is not what I expected.
I'm using Qt Designer to design gui and then I used the uic to generate c++ file.
in the c++ file it looks like this:
textEdit->setAutoFillBackground(false);
textEdit->setStyleSheet(QString::fromUtf8("background-color: rgb(109, 255, 99);"));
textEdit->setReadOnly(true);
Anybody know how to set the background color only for the area where text would be?
Thanks
All child objects of your text edit inherit the stylesheet, so all children (e.g. context menus) will have a green background.
You should select your QTextEdit only in your stylesheet, i.e.
textEdit->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");
Note that you can set the stylesheet at application level, too, so that all QTextEdit's in your app will have your specified background:
qApp->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");
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