目录
代码
运行
官方文档
PySide6.QtWidgets.QTabWidget - Qt for Python
代码
class TempWidget(QWidget):def __init__(self):super().__init__()self.tabs = QTabWidget()self.tabs.tabBarClicked.connect(self.tabs_tabBarClicked)widget_tab1 = QWidget()widget_tab2 = QWidget()widget_tab3 = QWidget()self.label0 = QLabel('tab1')self.label1 = QLabel('tab2')self.label2 = QLabel('tab3')layout1 = QHBoxLayout()layout1.addWidget(self.label0)layout2 = QHBoxLayout()layout2.addWidget(self.label1)layout3 = QHBoxLayout()layout3.addWidget(self.label2)widget_tab1.setLayout(layout1)widget_tab2.setLayout(layout2)widget_tab3.setLayout(layout3)self.tabs.addTab(widget_tab1,'tab1')self.tabs.addTab(widget_tab2,'tab2')self.tabs.addTab(widget_tab3,'tab3')self.label_below = QLabel('--', alignment=Qt.AlignmentFlag.AlignHCenter)layout = QVBoxLayout()layout.addWidget(self.tabs)layout.addWidget(self.label_below)self.setLayout(layout)passdef tabs_tabBarClicked(self,cur_i:int):self.label_below.setText(f'现在来到了 {self.tabs.tabText(cur_i)} 面板')pass