QTextEdit background color change also the color of scrollbar
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 (eg context menus) will have a green background.
You should select your QTextEdit only in your stylesheet, ie
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) }");
链接地址: http://www.djcxy.com/p/87630.html