我有一个三页的向导。第一页是BasicSettings()
,第二页是InstallPackages()
,最后一页是Summary()
我希望第一页上的Next按钮首先执行名为execute_venv_create()
的方法,然后调用下一页。在下面的页面中,下一步按钮应正常工作
为此,我将下一步按钮连接到execute_venv_create()
,如下所示:
class VenvWizard(QWizard):
"""The wizard class."""
def __init__(self):
super().__init__()
# ...
class BasicSettings(QWizardPage):
"""This is the first page."""
def __init__(self):
super().__init__()
# ...
def initializePage(self):
next_button = self.wizard().button(QWizard.NextButton)
next_button.clicked.connect(self.execute_venv_create)
def execute_venv_create(self):
# do something, then display an info message
QMessageBox.information(self, "Done", "message text")
当然,问题是每次单击Next时都会调用该方法,因此我尝试断开按钮的连接,并以这种方式将其重新连接到QWizard.next()
方法:
class InstallPackages(QWizardPage):
"""This is the second page."""
def __init__(self):
super().__init__()
# ...
def initializePage(self):
next_button = self.wizard().button(QWizard.NextButton)
next_button.disconnect()
next_button.clicked.connect(QWizard.next)
在第一页上,Next按钮按我的预期工作,它调用方法并切换到下一页。但是,在第二个页面InstallPackages()
,如果单击Next,GUI就会崩溃
这是将QWizard
按钮连接到自定义方法的正确方法,还是无法使用来自QWizardPages
的向导按钮
如何将QWizard.NextButton
连接到特定QWizardPage
的自定义方法,并使按钮在下面的页面上正常工作
您的方法是正确的,但必须使用与页面关联的QWizard对象,该对象可以通过^{} 方法获得:
相关问题 更多 >
编程相关推荐