问题描述
我一直在查看这个示例.我基于它编写了代码,但我仍然无法弄清楚如何连接 qwizard 的下一步按钮.例如,我希望每次单击下一个按钮时都打印页面的名称和编号.与完成按钮相同,当点击完成时,我希望它打印完成!"在控制台上,主要是了解如何连接这些按钮以执行其中一个页面中的功能.
I have been looking at this example. I wrote my code based on it but I still can't figure out how to connect the qwizard's next button. For example, I'd like it to print the page's name and number everytime the next button is clicked. Same with the finish button, when finish is clicked I would like it to print "finish!" on the console, mainly to know how to connect those buttons to execute a function in one of the pages.
推荐答案
可以通过函数{your Wizard}.button({type button})
获取按钮,其中按钮类型可以:
You can get the buttons through the function {your wizard}.button({type button})
, where button types can be:
- QtGui.QWizard.BackButton
- QtGui.QWizard.NextButton
- QtGui.QWizard.CommitButton
- QtGui.QWizard.FinishButton
- QtGui.QWizard.CancelButton
- QtGui.QWizard.HelpButton
- QtGui.QWizard.CustomButton1
- QtGui.QWizard.CustomButton2
- QtGui.QWizard.CustomButton3
代码:
from PyQt4 import QtGui
def createIntroPage():
page = QtGui.QWizardPage()
page.setTitle("Introduction")
label = QtGui.QLabel("This wizard will help you register your copy of "
"Super Product Two.")
label.setWordWrap(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
page.setLayout(layout)
return page
def createRegistrationPage():
page = QtGui.QWizardPage()
page.setTitle("Registration")
page.setSubTitle("Please fill both fields.")
nameLabel = QtGui.QLabel("Name:")
nameLineEdit = QtGui.QLineEdit()
emailLabel = QtGui.QLabel("Email address:")
emailLineEdit = QtGui.QLineEdit()
layout = QtGui.QGridLayout()
layout.addWidget(nameLabel, 0, 0)
layout.addWidget(nameLineEdit, 0, 1)
layout.addWidget(emailLabel, 1, 0)
layout.addWidget(emailLineEdit, 1, 1)
page.setLayout(layout)
return page
def createConclusionPage():
page = QtGui.QWizardPage()
page.setTitle("Conclusion")
label = QtGui.QLabel("You are now successfully registered. Have a nice day!")
label.setWordWrap(True)
layout = QtGui.QVBoxLayout()
layout.addWidget(label)
page.setLayout(layout)
return page
def backprint():
print("Action: back Page: " + wizard.currentPage().title())
def nextprint():
print("Action: next Page: " + wizard.currentPage().title())
def commitprint():
print("Action: commit Page: " + wizard.currentPage().title())
def finishprint():
print("Action:finish Page: " + wizard.currentPage().title())
def cancelprint():
print("Action:cancel Page: " + wizard.currentPage().title())
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
wizard = QtGui.QWizard()
wizard.addPage(createIntroPage())
wizard.addPage(createRegistrationPage())
wizard.addPage(createConclusionPage())
wizard.button(QtGui.QWizard.BackButton).clicked.connect(backprint)
wizard.button(QtGui.QWizard.NextButton).clicked.connect(nextprint)
wizard.button(QtGui.QWizard.CommitButton).clicked.connect(commitprint)
wizard.button(QtGui.QWizard.FinishButton).clicked.connect(finishprint)
wizard.button(QtGui.QWizard.CancelButton).clicked.connect(cancelprint)
wizard.setWindowTitle("Trivial Wizard")
wizard.show()
print("Page :" + wizard.currentPage().title())
sys.exit(wizard.exec_())
输出:
Page :Introduction
Action: next Page: Registration
Action: next Page: Conclusion
Action: back Page: Registration
Action: back Page: Introduction
Action: next Page: Registration
Action: next Page: Conclusion
Action:finish Page: Conclusion
这篇关于如何将页面的功能连接到 qwizard 的下一步按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!