user2494298
user2494298

Reputation: 299

Setting only background color of MainWindow Qt

So I am trying to change only the background color of my MainWindow. When I try to do this using this->setStyleSheet("background-color:black;"); for example it changes the background of everything: child widgets, QTextBoxEdit background, everything.

Is there a way to only change the background of just the main window?

Upvotes: 4

Views: 11990

Answers (2)

0xFFFFFFFF
0xFFFFFFFF

Reputation: 852

you can use Qt class name before QSS, like QMainWindow { background-color: rgb(0, 0, 0);}

in your example QMainWindow > QWidget { background-color: rgb(0, 0, 0);} maybe better.

please see http://doc.qt.io/qt-4.8/stylesheet-syntax.html for more information

Upvotes: 4

Tarod
Tarod

Reputation: 7170

As you know, every QMainWindow has a central widget and by default is named centralwidget.

So the best way of solving this issue is changing the background for that widget.

It's pretty simple when we use a style sheet. In this case would be the following one:

#centralwidget {
    background-color: rgb(0, 0, 0);
}

Upvotes: 4

Related Questions