[英]Changing the background color of QTabWidget
我目前有一个看起来像这样的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 */
}
关于如何在标签下添加背景色的任何建议将不胜感激。 谢谢。
您可以在构造函数中使用stStyleSheet:
ui->YOURWIDGET->setStyleSheet("background-color: YOURCOLOR");
为了使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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.