class HorizontalTabBar(QtWidgets.QTabBar):
def __init__(self, *args, **kwargs):
super(HorizontalTabBar, 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(QtWidgets.QStyle.CE_TabBarTabShape, option)
painter.drawText(tabRect, QtCore.Qt.AlignVCenter | QtCore.Qt.TextDontClip, self.tabText(index))
painter.end()
import sys
app = QtGui.QApplication(sys.argv)
tabs = QtGui.QTabWidget()
tabs.setTabBar(HorizontalTabBar())
widget1 = QtGui.QWidget()
widget2 = QtGui.QWidget()
tabs.addTab(widget1, "Widget1")
tabs.addTab(widget2, "Widget2")
tabs.setTabPosition(2)
tabs.show()
sys.exit(app.exec_())
设置QTabWidget标题页纵向文字横向排列的写法
最新推荐文章于 2024-07-08 15:48:58 发布