PySide2 QWizard 非线性页面
PySide2 QWizard non linear pages
我正在尝试将我的代码从 PyQt5 更改为 PySide2。我的大部分脚本只需将导入从 PyQt5 更改为 PySide2,它的工作原理是一样的。但是,我尝试将 Qt 文档中的许可向导示例从 PyQt5 修改为 PySide2。在 PyQt5 中,它工作得很好,但是,在 PySide2 中,我收到一个错误,退出代码为 139(被信号 11 中断:SIGSEGV)。线性向导的 PySide2 qwizard 代码(如 class 向导示例)工作正常。有谁知道为什么非线性向导会失败以及为什么我会收到该错误?
谢谢
以下代码适用于 PyQt5。用 PySide2 替换 PyQt5 我得到一个错误
进程已完成,退出代码为 132(被信号 4 中断:SIGILL)
class IntroductionPage(QtWidgets.QWizardPage):
def __init__(self):
super(IntroductionPage, self).__init__()
self.setTitle("Introduction")
self.label = QtWidgets.QLabel("set this up")
self.label.setWordWrap(True)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def nextId(self):
return Wizard.class1
class ClassesPage1(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage1, self).__init__()
self.setTitle("Choices")
self.setSubTitle("Choose 1")
self.radButton1 = QtWidgets.QRadioButton('1A')
self.radButton2 = QtWidgets.QRadioButton('1B')
self.radButton3 = QtWidgets.QRadioButton('1C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected1 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
if self.radButton2.isChecked():
return Wizard.class2
elif self.radButton3.isChecked():
return Wizard.class2
else:
return Wizard.conclusion
class ClassesPage2(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage2, self).__init__()
#self.page = QWizardPage()
self.setTitle("Classes for grade 2")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('2A')
self.radButton2 = QtWidgets.QRadioButton('2B')
self.radButton3 = QtWidgets.QRadioButton('2C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected2 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ClassesPage3(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage3, self).__init__()
self.setTitle("Classes for grade 3")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('3A')
self.radButton2 = QtWidgets.QRadioButton('3B')
self.radButton3 = QtWidgets.QRadioButton('3C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected3 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ConclusionPage(QtWidgets.QWizardPage):
def __init__(self):
super(ConclusionPage, self).__init__()
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.label2 = QtWidgets.QLabel(self)
self.layout.addWidget(self.label)
self.layout.addWidget(self.label2)
self.setLayout(self.layout)
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self):
super(Wizard, self).__init__()
self.setPage(self.intro, IntroductionPage())
self.setPage(self.class1, ClassesPage1())
self.setPage(self.class2, ClassesPage2())
self.setPage(self.class3, ClassesPage3())
self.setPage(self.conclusion, ConclusionPage())
self.setStartId(self.intro)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
wizard = Wizard()
wizard.setWindowTitle("Set Up")
wizard.setWizardStyle(QtWidgets.QWizard.MacStyle)
wizard.show()
sys.exit(app.exec_())
似乎与 PyQt5 不同,PySide2 要求您传递父级,在您的情况下,解决方案是更改 类:
的构造函数
class Some_Page(QtWidgets.QWizardPage):
def __init__(self):
super(Some_Page, self).__init__()
至:
class Some_Page(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(Some_Page, self).__init__(*args, **kwargs)
我们在添加页面的时候,把parent传给他:
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self, *args, **kwargs):
super(Wizard, self).__init__(*args, **kwargs)
self.setPage(self.intro, IntroductionPage(self))
self.setPage(self.class1, ClassesPage1(self))
self.setPage(self.class2, ClassesPage2(self))
self.setPage(self.class3, ClassesPage3(self))
self.setPage(self.conclusion, ConclusionPage(self))
self.setStartId(self.intro)
完整代码:
from PySide2 import QtWidgets
import sys
class IntroductionPage(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(IntroductionPage, self).__init__(*args, **kwargs)
self.setTitle("Introduction")
self.label = QtWidgets.QLabel("Welcome to the One Inc™'s Teacher Interactive Accessment tool. Follow the prompts to set up your Mark Sheet")
self.label.setWordWrap(True)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def nextId(self):
return Wizard.class1
class ClassesPage1(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage1, self).__init__(*args, **kwargs)
self.setTitle("Choices")
self.setSubTitle("Choose 1")
self.radButton1 = QtWidgets.QRadioButton('1A')
self.radButton2 = QtWidgets.QRadioButton('1B')
self.radButton3 = QtWidgets.QRadioButton('1C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.setLayout(self.layout)
def nextId(self):
if self.radButton2.isChecked():
return Wizard.class2
elif self.radButton3.isChecked():
return Wizard.class2
else:
return Wizard.conclusion
class ClassesPage2(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage2, self).__init__(*args, **kwargs)
#self.page = QWizardPage()
self.setTitle("Classes for grade 2")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('2A')
self.radButton2 = QtWidgets.QRadioButton('2B')
self.radButton3 = QtWidgets.QRadioButton('2C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected2 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ClassesPage3(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage3, self).__init__(*args, **kwargs)
self.setTitle("Classes for grade 3")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('3A', self)
self.radButton2 = QtWidgets.QRadioButton('3B', self)
self.radButton3 = QtWidgets.QRadioButton('3C', self)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected3 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ConclusionPage(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ConclusionPage, self).__init__(*args, **kwargs)
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.label2 = QtWidgets.QLabel(self)
self.layout.addWidget(self.label)
self.layout.addWidget(self.label2)
self.setLayout(self.layout)
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self, *args, **kwargs):
super(Wizard, self).__init__(*args, **kwargs)
self.setPage(self.intro, IntroductionPage(self))
self.setPage(self.class1, ClassesPage1(self))
self.setPage(self.class2, ClassesPage2(self))
self.setPage(self.class3, ClassesPage3(self))
self.setPage(self.conclusion, ConclusionPage(self))
self.setStartId(self.intro)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
wizard = Wizard()
wizard.setWindowTitle("Set Up")
wizard.setWizardStyle(QtWidgets.QWizard.MacStyle)
wizard.show()
sys.exit(app.exec_())
我正在尝试将我的代码从 PyQt5 更改为 PySide2。我的大部分脚本只需将导入从 PyQt5 更改为 PySide2,它的工作原理是一样的。但是,我尝试将 Qt 文档中的许可向导示例从 PyQt5 修改为 PySide2。在 PyQt5 中,它工作得很好,但是,在 PySide2 中,我收到一个错误,退出代码为 139(被信号 11 中断:SIGSEGV)。线性向导的 PySide2 qwizard 代码(如 class 向导示例)工作正常。有谁知道为什么非线性向导会失败以及为什么我会收到该错误?
谢谢
以下代码适用于 PyQt5。用 PySide2 替换 PyQt5 我得到一个错误
进程已完成,退出代码为 132(被信号 4 中断:SIGILL)
class IntroductionPage(QtWidgets.QWizardPage):
def __init__(self):
super(IntroductionPage, self).__init__()
self.setTitle("Introduction")
self.label = QtWidgets.QLabel("set this up")
self.label.setWordWrap(True)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def nextId(self):
return Wizard.class1
class ClassesPage1(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage1, self).__init__()
self.setTitle("Choices")
self.setSubTitle("Choose 1")
self.radButton1 = QtWidgets.QRadioButton('1A')
self.radButton2 = QtWidgets.QRadioButton('1B')
self.radButton3 = QtWidgets.QRadioButton('1C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected1 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
if self.radButton2.isChecked():
return Wizard.class2
elif self.radButton3.isChecked():
return Wizard.class2
else:
return Wizard.conclusion
class ClassesPage2(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage2, self).__init__()
#self.page = QWizardPage()
self.setTitle("Classes for grade 2")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('2A')
self.radButton2 = QtWidgets.QRadioButton('2B')
self.radButton3 = QtWidgets.QRadioButton('2C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected2 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ClassesPage3(QtWidgets.QWizardPage):
def __init__(self):
super(ClassesPage3, self).__init__()
self.setTitle("Classes for grade 3")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('3A')
self.radButton2 = QtWidgets.QRadioButton('3B')
self.radButton3 = QtWidgets.QRadioButton('3C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected3 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ConclusionPage(QtWidgets.QWizardPage):
def __init__(self):
super(ConclusionPage, self).__init__()
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.label2 = QtWidgets.QLabel(self)
self.layout.addWidget(self.label)
self.layout.addWidget(self.label2)
self.setLayout(self.layout)
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self):
super(Wizard, self).__init__()
self.setPage(self.intro, IntroductionPage())
self.setPage(self.class1, ClassesPage1())
self.setPage(self.class2, ClassesPage2())
self.setPage(self.class3, ClassesPage3())
self.setPage(self.conclusion, ConclusionPage())
self.setStartId(self.intro)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
wizard = Wizard()
wizard.setWindowTitle("Set Up")
wizard.setWizardStyle(QtWidgets.QWizard.MacStyle)
wizard.show()
sys.exit(app.exec_())
似乎与 PyQt5 不同,PySide2 要求您传递父级,在您的情况下,解决方案是更改 类:
的构造函数class Some_Page(QtWidgets.QWizardPage):
def __init__(self):
super(Some_Page, self).__init__()
至:
class Some_Page(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(Some_Page, self).__init__(*args, **kwargs)
我们在添加页面的时候,把parent传给他:
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self, *args, **kwargs):
super(Wizard, self).__init__(*args, **kwargs)
self.setPage(self.intro, IntroductionPage(self))
self.setPage(self.class1, ClassesPage1(self))
self.setPage(self.class2, ClassesPage2(self))
self.setPage(self.class3, ClassesPage3(self))
self.setPage(self.conclusion, ConclusionPage(self))
self.setStartId(self.intro)
完整代码:
from PySide2 import QtWidgets
import sys
class IntroductionPage(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(IntroductionPage, self).__init__(*args, **kwargs)
self.setTitle("Introduction")
self.label = QtWidgets.QLabel("Welcome to the One Inc™'s Teacher Interactive Accessment tool. Follow the prompts to set up your Mark Sheet")
self.label.setWordWrap(True)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
def nextId(self):
return Wizard.class1
class ClassesPage1(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage1, self).__init__(*args, **kwargs)
self.setTitle("Choices")
self.setSubTitle("Choose 1")
self.radButton1 = QtWidgets.QRadioButton('1A')
self.radButton2 = QtWidgets.QRadioButton('1B')
self.radButton3 = QtWidgets.QRadioButton('1C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.setLayout(self.layout)
def nextId(self):
if self.radButton2.isChecked():
return Wizard.class2
elif self.radButton3.isChecked():
return Wizard.class2
else:
return Wizard.conclusion
class ClassesPage2(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage2, self).__init__(*args, **kwargs)
#self.page = QWizardPage()
self.setTitle("Classes for grade 2")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('2A')
self.radButton2 = QtWidgets.QRadioButton('2B')
self.radButton3 = QtWidgets.QRadioButton('2C')
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected2 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ClassesPage3(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ClassesPage3, self).__init__(*args, **kwargs)
self.setTitle("Classes for grade 3")
self.setSubTitle("Please select a Class")
self.radButton1 = QtWidgets.QRadioButton('3A', self)
self.radButton2 = QtWidgets.QRadioButton('3B', self)
self.radButton3 = QtWidgets.QRadioButton('3C', self)
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.radButton1)
self.layout.addWidget(self.radButton2)
self.layout.addWidget(self.radButton3)
self.class_selected3 = QtWidgets.QLineEdit()
self.setLayout(self.layout)
def nextId(self):
return Wizard.conclusion
class ConclusionPage(QtWidgets.QWizardPage):
def __init__(self, *args, **kwargs):
super(ConclusionPage, self).__init__(*args, **kwargs)
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel(self)
self.label2 = QtWidgets.QLabel(self)
self.layout.addWidget(self.label)
self.layout.addWidget(self.label2)
self.setLayout(self.layout)
class Wizard(QtWidgets.QWizard):
num_of_pages = 5
(intro, class1, class2, class3, conclusion) = range(num_of_pages)
def __init__(self, *args, **kwargs):
super(Wizard, self).__init__(*args, **kwargs)
self.setPage(self.intro, IntroductionPage(self))
self.setPage(self.class1, ClassesPage1(self))
self.setPage(self.class2, ClassesPage2(self))
self.setPage(self.class3, ClassesPage3(self))
self.setPage(self.conclusion, ConclusionPage(self))
self.setStartId(self.intro)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
wizard = Wizard()
wizard.setWindowTitle("Set Up")
wizard.setWizardStyle(QtWidgets.QWizard.MacStyle)
wizard.show()
sys.exit(app.exec_())