我想僅對特定選項卡進行更改。我該怎麼做?在qt中自定義樣式表中的選項卡控件
我都嘗試:
QTabBar::tab#tbGeneral{... }
QTabWidget::tab-bar#tbGeneral{... }
無工作。
我想僅對特定選項卡進行更改。我該怎麼做?在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