Changing the background color QTextEdit also has a scroll bar color

I want the QtextEdit in my application to be green, so I set the stylesheet

background-color: rgb(109, 255, 99);

However, this also changes the background color of the scroll bars and even when I press the right mouse button in text mode, the menu displayed is also green, and this is not what I expected.

I use Qt Designer to create a gui, and then I used uic to create a C ++ file.

in a C ++ file is as follows:

textEdit->setAutoFillBackground(false);
textEdit->setStyleSheet(QString::fromUtf8("background-color: rgb(109, 255, 99);"));
textEdit->setReadOnly(true);

Does anyone know how to set the background color only for the area where the text will be?

thank

+5
source share
1 answer

All children of your text editing will inherit the style sheet, so all children (for example, context menus) will have a green background.

QTextEdit , ..

textEdit->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");

, , QTextEdit :

qApp->setStyleSheet("QTextEdit { background-color: rgb(109, 255, 99) }");
+9

All Articles