I was trying to display my QTabWidget
text horizontally with the Tabposition
set to 2 (left side). After searching around, i found the following code from this link.
class FingerTabWidget(QtGui.QTabBar):
def __init__(self, *args, **kwargs):
self.tabSize = QtCore.QSize(kwargs.pop('width'), kwargs.pop('height'))
super(FingerTabWidget, self).__init__(*args, **kwargs)
def paintEvent(self, event):
painter = QtGui.QStylePainter(self)
option = QtGui.QStyleOptionTab()
painter.begin(self)
for index in range(self.count()):
self.initStyleOption(option, index)
tabRect = self.tabRect(index)
tabRect.moveLeft(10)
painter.drawControl(QtGui.QStyle.CE_TabBarTabShape, option)
painter.drawText(tabRect, QtCore.Qt.AlignVCenter | QtCore.Qt.TextDontClip, self.tabText(index));
painter.end()
def tabSizeHint(self,index):
return self.tabSize
I managed to apply this code by just simply using this
Tab = QtGui.QTabWidget()
Tab.setTabBar(FingerTabWidget(width=260,height=28))
Everything looks exactly like i expected and working fine but i am keep getting this error message everytime i mouse over on one of the tab.
QPainter::begin: Painter already active
Even though it does not affect the functionality of my program, i would like to know what is causing this error message. A simple explanation will do.