事實上,Qt有很好的文檔,很好的例子,所有here。 Main page to stylesheets.
所有你需要做的是設置樣式要麼QtDesigner
或Python本身,就像這樣:
self.tabWidget.setStyleSheet("background-color: rgb(255, 255, 255);\n"
"border:1px solid rgb(255, 170, 255);")
下面是一個簡單的樣式表(從Qtabwidget
第三例)
QTabWidget::pane { /* The tab widget frame */
border-top: 2px solid #C2C7CB;
position: absolute;
top: -0.5em;
}
QTabWidget::tab-bar {
alignment: center;
}
/* Style the tab using the tab sub-control. Note that
it reads QTabBar _not_ QTabWidget */
QTabBar::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
border: 2px solid #C4C4C3;
border-bottom-color: #C2C7CB; /* same as the pane color */
border-top-left-radius: 4px;
border-top-right-radius: 4px;
min-width: 8ex;
padding: 2px;
}
QTabBar::tab:selected, QTabBar::tab:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 0.4 #f4f4f4,
stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
}
QTabBar::tab:selected {
border-color: #9B9B9B;
border-bottom-color: #C2C7CB; /* same as pane color */
}
對,我意識到這一點,但使用所有的選項卡將完全相同。每個選項卡將具有相同的樣式表。如果我有5個選項卡,並且我希望其中一個具有完全不同的樣式表,那麼另一個(不包括選定/懸停的選項卡)。 – user2444217
你有沒有看過像這樣的'QTabBar :: tab:first'作爲選擇器? – enginefree
啊哈!對不起,那是我的愚蠢。這解決了它。非常感謝你:) – user2444217