Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTextEdit background color change also the color of scrollbar

Tags:

c++

qt

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

like image 555
Jan Avatar asked Mar 04 '12 11:03

Jan


1 Answers

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) }");
like image 58
Chris Browet Avatar answered Sep 20 '22 12:09

Chris Browet