我想在QWizard
中存储一些数据,然后从QWizardPages
访问它。但是,当我试图从QWizardPage
访问数据时,它的父类型在代码执行期间从QWizard
更改为{QWizardPages
中的任何一个访问存储在父QWizard
中的数据?在
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_()
由于您在创建页面时将
QWizard
的引用传递给QWizardPage
,因此您只需存储此引用并在以后使用它(请参见figs的注释)。在或者,您可以使用}中访问{},这可能正是因为这个原因(父元素在内部发生了变化)。在
wizard()
方法(在Avaris的注释中提到)从{相关问题 更多 >
编程相关推荐