我想在QWizard
中存储一些数据,然后从QWizardPages
访问它。但是,当我尝试从QWizardPage
访问数据时,它的父类型在代码执行期间从QWizard
更改为QForm
,因此我无法再以这种方式访问父数据。为什么会如此?如何从QWizard
中的任何一个可靠地访问存储在父QWizardPages
中的数据?
from PyQt4 import QtGui
from PyQt4.QtGui import QLabel, QVBoxLayout
class WizardExample(QtGui.QWizard):
def __init__(self, parent=None):
super(WizardExample, self).__init__(parent)
self.setObjectName("WizardExample")
self.setWindowTitle('Wizard example')
#check data source once and store result
self._dataExists = False
self.addPage(Page1(self))
class Page1(QtGui.QWizardPage):
def __init__( self, parent ):
super(Page1, self).__init__(parent)
layout = QVBoxLayout()
self.setTitle('Page1')
self.label = QLabel("Text entry... ")
self.setObjectName("Page1")
layout.addWidget(self.label)
self.setLayout(layout)
print("--__init__() parent()._dataExists: "+str(self.parent()._dataExists))
self.printTypes()
def printTypes(self):
print(">>printTypes() self name: "+str(self.objectName())+" self type: "+str(type(self))+" parent name: "+self.parent().objectName()+" parent type: "+str(type(self.parent())))
def isComplete(self):
print(">>isComplete()")
self.printTypes()
#fails on the following call
if self.parent()._dataExists:
return True
else:
return False
class AppWindow(QtGui.QMainWindow):
def __init__( self, parent = None ):
super(AppWindow, self).__init__(parent)
wizard = WizardExample(self)
wizard.exec_()
if ( __name__ == '__main__' ):
app = None
if ( not QtGui.QApplication.instance() ):
app = QtGui.QApplication([])
window = AppWindow()
window.show()
if ( app ):
app.exec_()