想初始化下图的红色圈内的区域,必须在代码中添加
ui->tabSampleQc->setAttribute(Qt::WA_StyledBackground);
然后在qss中添加以下代码
/*设置控件的背景*/
QTabWidget
{
background-color:rgb(104,191,249);
}
/*设置控件下面板的背景颜色*/
QTabWidget::pane
{
background-color: rgb(228, 233, 242);
border:none;
}
/*设置控件下选择页的颜色*/
QTabBar::tab
{
font: 15pt "Chinese fine black";
background-color:rgb(104,191,249);
min-width: 60px;
min-height: 30px;
padding: 2px;
}
/*设置控件下选择页被选中的颜色*/
QTabBar::tab:selected
{
background-color: rgb(228, 233, 242);
}
在一个工程中想设置特定的QTabWidget控件背景颜色时,可以使用以下的qss代码
/*设置对象名为TW_SampleResult的QTabWidget控件*/
QTabWidget#TW_SampleResult>QTabBar::tab
{
font: 15pt "Chinese fine black";
background-color:rgb(104,191,249);
min-width: 100px;
min-height: 30px;
padding: 2px;
}
/*设置对象名为TW_SampleResult的QTabWidget控件*/
QTabWidget#TW_SampleResult>QTabBar::tab:selected
{
background-color: rgb(228, 233, 242);
}
QTabBar::tab:selected
{
background-color: rgb(228, 233, 242);
}