PDA

View Full Version : [pyqt] Customizing QTabBar in QTabWidget..



pyqt123
14th December 2009, 14:13
Hello all,
1) I want to have a Tabbed widget with some spaces between it's tab bars(ie., between adjacent tab headers).. And i learnt that we can customize the tab widget if we use QTabBar with stylesheets like left-margin and right-margin etc.. So i created a tab bar and attatched it with the QTabWidget.. But when i set the style sheet for QTabBar it didn't show up.. Do i have to do this for every instance of tabs in the QTabBar(If yes then how can i catch the instance for tab1)???
But here in this link http://doc.trolltech.com/4.3/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar (http://doc.trolltech.com/4.3/stylesheet-examples.html#customizing-qtabwidget-and-qtabbar) theyr'e creating the styles globally for the TabBar..

And this program isn't working as intended...

from PyQt4 import QtCore, QtGui
import sys

class Ui_TabWidget(object):
def setupUi(self, TabWidget):
TabWidget.setObjectName("TabWidget")
TabWidget.resize(400, 300)

self.tabBar=QtGui.QTabBar(TabWidget)

self.tabBar.setStyleSheet("QTabBar{left-margin:20;right-margin:20;}")

self.tabBar.addTab("Tab1")
self.tabBar.setTabText(0,"hello")

self.tabBar.addTab("Tab2")
self.tabBar.setTabText(1,"hai")

TabWidget.setTabBar(self.tabBar)

self.retranslateUi(TabWidget)

QtCore.QMetaObject.connectSlotsByName(TabWidget)

def retranslateUi(self, TabWidget):
TabWidget.setWindowTitle(QtGui.QApplication.transl ate("TabWidget", "TabWidget", None, QtGui.QApplication.UnicodeUTF8))


app = QtGui.QApplication(sys.argv)

TabWidget = QtGui.QTabWidget()
ui = Ui_TabWidget()
ui.setupUi(TabWidget)
TabWidget.show()
sys.exit(app.exec_())
May i know where i did mistake??

2) I want to show the Tab header of the selected tab in different color gradient.. Can you please tell me how to set the different colors for tab-headers???
Any help in this regard would be great..Thanks..