我目前有一个看起来像this.The QTabWidget的QtabWidget,里面有一个QtableView

我想知道怎样才能改变QtabWidget的背景颜色。我希望保留现有的QtabWidget样式表,并且只在红色箭头标记的区域中添加蓝色背景。简而言之,我想在标签下面添加一个背景色。我目前有一个样式表,如下所示
QTAB
QTabWidget
{
/* min-width:5000em;*/
}
QTabWidget::tab-bar
{
left: 5px; /* move to the right by 5px */
}
QTabWidget::pane
{
border-top: 1px solid gray;
border-left: 1px solid gray;
border-right: 1px solid gray;
border-bottom: 1px solid gray;
}
QTabBar::tab
{
background-color: rgb(166, 166, 166);
min-width: 70px;
padding-top : 6px;
padding-bottom : 8px;
color: rgb(255, 255, 255);
font: 10pt "Arial";
}
QTabBar::tab:selected, QTabBar::tab:hover
{
background-color: rgb(127, 127, 127);
}
QTabBar::tab:selected
{
/*border-color: #9B9B9B;*/
}
QTabBar::tab:!selected
{
margin-top: 2px; /* make non-selected tabs look smaller */
}任何关于如何在标签下添加背景颜色的建议都将不胜感激。谢谢。
发布于 2014-05-20 05:23:35
您可以在构造函数中使用stStyleSheet:
ui->YOURWIDGET->setStyleSheet("background-color: YOURCOLOR");发布于 2015-03-05 14:11:31
为了使QWidget的子类在背景颜色上工作,您需要覆盖此函数
def paintEvent(self, event):
o = QtGui.QStyleOption()
o.initFrom(self)
p = QtGui.QPainter(self)
self.style().drawPrimitive(QtGui.QStyle.PE_Widget, o, p, self)https://stackoverflow.com/questions/23709091
复制相似问题