Change StyleSheet of QToolBox in Qt

2019-08-21 20:37发布

问题:

I am designing a GUI in Qt. I have a MainWindow and a QToolBox in it. The class of my MainWindow is QTabWidget.

According to the following pictures, I have a QToolBox with two tab named Encoder and Decoder.

I could change the background color of each tab and its border.

But I don't know how to change the color of background of each pane/tab.

For example I want to change the color of Decoder pane to blue as follow.

It is possible to put a frame-widget to page and change its background.

But is it possible to change the stylesheet of QToolBox directly.

回答1:

Use this stylesheet to access certain pages in QToolBox:

QWidget#page,
QWidget#page_2,
{
  background: blue
}

Where page and page_2 are object names of your pages. You can find them in QtDesigner - currentItemName.

Or use this stylesheet to apply changes to all pages:

QToolBox QScrollArea>QWidget>QWidget
{
  background: blue;
}


回答2:

Have you tried:

QToolBox tb;
tb.setStyleSheet("background-color: blue");

If that won't do for you, there is a good list of examples on Qt Style Sheets. Maybe you can find what you want from here.