customizing tab control in stylesheet in qt
I would like to do changes only for a specific tab. How can I do it?
I tried both:
QTabBar::tab#tbGeneral{... }
QTabWidget::tab-bar开发者_如何学编程#tbGeneral{... }
None worked.
You have probably looked into Customizing QTabWidget and QTabBar.
To style individual tabs based on their state (:only-one, :first, :last, :middle, :previous-selected, :next-selected, :selected) you can use stylesheet-code similar to this:
QTabBar::tab {
border: 1px solid #C4C4C3;
border-bottom-color: #C2C7CB;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
padding: 1px 3px;
margin-left: 1px;
margin-bottom: 4px;
}
QTabBar::tab:selected {
background-color: #f14040;
border-bottom-style: none;
}
As the individual tabs are not widgets (or objects), they have no object name or other properties that could identify them to a stylsheet. You can only use the pseudo-classes to style tabs with a stylesheet.
You'll probably have to use (C++) code to change the style of a tab depending on the label. The recommended way for customizing styles in Qt is through the class QStyle
. You can either subclass QStyle
or use QProxyStyle
to change the looks of specific widgets. The other alternative (probably not recommended by Qt) is though subclassing QTabBar and reimplementing the function QWidget::paintEvent( QPaintEvent *event)
.
精彩评论