在qt中自定义样式表中的选项卡控件
问题描述:
我想仅对特定选项卡进行更改。我该怎么做?在qt中自定义样式表中的选项卡控件
我都尝试:
QTabBar::tab#tbGeneral{... }
QTabWidget::tab-bar#tbGeneral{... }
无工作。
答
您可能已经调查过Customizing QTabWidget and 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;
}
由于各个选项卡都没有的小部件(或对象),他们有没有对象的名称或可识别他们的stylsheet其他属性。您只能使用伪类来设置样式表的样式。
您可能必须使用(C++)代码才能根据标签更改选项卡的样式。在Qt中定制样式的建议方法是通过QStyle
。您可以继承QStyle
的子类或使用QProxyStyle
更改特定小部件的外观。另一种选择(可能不是由Qt推荐)是通过子类化QTabBar并重新实现函数QWidget::paintEvent(QPaintEvent *event)
。
你绝对需要使用样式表还是可以在代码中使用样式表? – Live 2010-11-03 14:48:46