Tab Widget - Tab Height to accommodate 2-line tab names?
-
PyQt4 and/or PySide / Python 3 / Windows
Is it possible to resize the height of a tab bar in order to fit 2-lines of text in the tab names?
(Better yet, is it possible to have a tab bar resize its height dynamically based on the number of lines of text?)
Thanks
-
You could do this using style sheets to get a static height, however the following method shows how to have the tab bar dynamically size to the text by inserting QLabels:
@
from PyQt4.QtGui import *class TabWidget(QTabWidget):
def addTab(self, widget, text):
i=QTabWidget.addTab(self, widget, "")
self.tabBar().setTabButton(i, QTabBar.LeftSide, QLabel(text, self))class Widget(QWidget):
def init(self, parent=None):
QWidget.init(self, parent)l=QVBoxLayout(self) t=TabWidget(self) t.addTab(QWidget(self), "Tab\n1") t.addTab(QWidget(self), "Tab 2") t.addTab(QWidget(self), "Tab\n3") l.addWidget(t)
if name=="main":
from sys import argv, exit
a=QApplication(argv)
w=Widget()
w.show()
w.raise_()
exit(a.exec_())
@Hope this helps.