示例代码
代码语言:python
代码运行次数:0
复制from __future__ import annotations
import sys
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget, QWizard, QWizardPage
class MyWizardPage(QWizardPage):
def __init__(self, title: str = '', content: str = ''):
super().__init__()
self.setTitle(title)
self.setSubTitle('{} 的操作步骤'.format(title))
self.v_layout = QVBoxLayout()
label = QLabel(content)
self.v_layout.addWidget(label)
self.setLayout(self.v_layout)
class MainWizard(QWizard):
def __init__(self):
super().__init__()
self.setWindowTitle('QWizard示例')
self.addPage(MyWizardPage('1. 创建项目', '这是关于创建项目的内容'))
self.addPage(MyWizardPage('2. 添加文件', '这是关于添加文件的内容'))
self.addPage(MyWizardPage('3. 编译项目', '这是关于编译项目的内容'))
self.addPage(MyWizardPage('4. 运行项目', '这是关于运行项目的内容'))
def open_wizard():
wizard = MainWizard()
wizard.exec()
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('QWizard示例')
self.setCentralWidget(MyWizardPage('1. 创建项目', '这是关于创建项目的内容'))
button = QPushButton('打开向导')
button.clicked.connect(open_wizard)
v_layout = QVBoxLayout()
v_layout.addWidget(button)
container = QWidget()
container.setLayout(v_layout)
self.setCentralWidget(container)
if __name__ == '__main__':
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec())
运行效果