Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting only background color of MainWindow Qt

Tags:

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?

like image 820
user2494298 Avatar asked Feb 14 '23 22:02

user2494298


1 Answers

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);
}
like image 171
Tarod Avatar answered Jun 13 '23 21:06

Tarod