【发布时间】:2014-09-22 23:36:35
【问题描述】:
我正在 PySide 中构建一个 QWidget,但在尝试在页面之间共享数据时遇到了问题。
总而言之,我利用之前页面中的用户输入来构建自定义对象列表,我需要将其与下一页共享。
在我的代码的开头,我构造了一个自定义对象,具有一个名为 .name 的属性(以及其他属性)
class MyCustomClass():
def __init__(self, name, other_attributes)
self.name = name
...set other attributes
在我的 QWizard 中,我打开一个文件并创建一个名称列表以匹配另一个 MyCustomClass 对象列表。然后,我在对应的MyCustomClass 对象的匹配name 旁边显示名称,并提示用户确认(或更改),然后再转到下一页。
每个匹配项都存储为tuple(name, MyCustomClass) 并添加到列表中。然后我希望从下一页阅读此列表以执行更多操作。我正在尝试使用 .registerField,但我不确定如何正确使用。我的尝试如下。
首先我创建一个QWizardPage,执行一些代码,然后构建我的匹配项。我做了一个函数来返回值并将它用于.registerField
class ConfirmMatches(QWizardPage):
def __init__(self):
...
def initializePage(self):
# Code to make display and operations and make list of matches
...
self.matches = matches
self.registerField("matches", self, "get_matches")
def get_matches(self):
return self.matches
然后从我的下一页,我尝试调用该字段,但我只返回一个 None 对象。
class NextPage(QWizardPage):
def __init__(self):
...
def initializePage(self):
# Get relevant fields from past pages
past_matches = self.field("matches")
type(past_matches) 是None,尽管我在上一页中print self.matches 时清楚地显示了它们。
我在
registerField上做错了什么?是否有更简单的方法在页面之间共享此类数据?
【问题讨论】:
-
你检查了QWizard examples吗?
标签: python-3.x pyqt pyside