2013-08-05 202 views
0

我正在使用QTabWidget与多个选项卡。我想创建一个不同的标签(具有不同的样式,然后是其他标签)。例如,firefox如何使用绿色加号按钮来添加与其他选项卡不同的新选项卡。PySide自定义选项卡

我正在浏览文档,找不到与选项卡的独特样式相关的任何内容。我看着QTabWidget和QTabBar,但没有运气。

这是我如何创建标签

self.tabWidget = QtGui.QTabWidget() 
self.tabWidget.addTab(QtGui.QWidget, "Tab_1") 

有什么我都忽略了?

回答

5

事实上,Qt有很好的文档,很好的例子,所有hereMain 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 */ 
} 
+0

对,我意识到这一点,但使用所有的选项卡将完全相同。每个选项卡将具有相同的样式表。如果我有5个选项卡,并且我希望其中一个具有完全不同的样式表,那么另一个(不包括选定/悬停的选项卡)。 – user2444217

+2

你有没有看过像这样的'QTabBar :: tab:first'作为选择器? – enginefree

+0

啊哈!对不起,那是我的愚蠢。这解决了它。非常感谢你:) – user2444217