我想仅针对特定选项卡进行更改。 我该怎么做?
我试过了两个:
QTabBar::tab#tbGeneral{... } QTabWidget::tab-bar#tbGeneral{... }没有用。
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.
最满意答案
您可能已经研究过Customizing QTabWidget和QTabBar 。
要根据各个选项卡的状态设置样式(:only-one,:first,:last,:middle,:previous-selected,:next-selected,:selected),您可以使用与此类似的样式表代码:
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; }由于各个选项卡不是窗口小部件(或对象),因此它们没有对象名称或其他可以将它们标识到样式表的属性。 您只能使用伪类来设置样式表的样式。
您可能必须使用(C ++)代码来根据标签更改选项卡的样式。 在Qt中自定义样式的推荐方法是通过类QStyle 。 您可以子类化QStyle或使用QProxyStyle来更改特定小部件的外观。 另一个替代方案(可能不是Qt推荐的)是通过继承QTabBar并重新实现函数QWidget::paintEvent( QPaintEvent *event) 。
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).
更多推荐
发布评论