gpt4 book ai didi

python - PyQt5如何设置TabWidget向西但保持文本水平

转载 作者:太空宇宙 更新时间:2023-11-03 10:50:36 28 4
gpt4 key购买 nike

enter image description here

如何使文本方向从左到右而不是从上到下

最佳答案

在这个回答中,我将对我的 another answer 进行 Python 翻译。用 C++ 编写。

from PyQt5 import QtCore, QtGui, QtWidgets


class TabBar(QtWidgets.QTabBar):
def tabSizeHint(self, index):
s = QtWidgets.QTabBar.tabSizeHint(self, index)
s.transpose()
return s

def paintEvent(self, event):
painter = QtWidgets.QStylePainter(self)
opt = QtWidgets.QStyleOptionTab()

for i in range(self.count()):
self.initStyleOption(opt, i)
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabShape, opt)
painter.save()

s = opt.rect.size()
s.transpose()
r = QtCore.QRect(QtCore.QPoint(), s)
r.moveCenter(opt.rect.center())
opt.rect = r

c = self.tabRect(i).center()
painter.translate(c)
painter.rotate(90)
painter.translate(-c)
painter.drawControl(QtWidgets.QStyle.CE_TabBarTabLabel, opt);
painter.restore()


class TabWidget(QtWidgets.QTabWidget):
def __init__(self, *args, **kwargs):
QtWidgets.QTabWidget.__init__(self, *args, **kwargs)
self.setTabBar(TabBar(self))
self.setTabPosition(QtWidgets.QTabWidget.West)


if __name__ == '__main__':
import sys

app = QtWidgets.QApplication(sys.argv)
w = TabWidget()
w.addTab(QtWidgets.QWidget(), "tab1")
w.addTab(QtWidgets.QWidget(), "tab2")
w.addTab(QtWidgets.QWidget(), "tab3")
w.show()

sys.exit(app.exec_())

关于python - PyQt5如何设置TabWidget向西但保持文本水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51230544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com