问题描述:

I am working on a PyQt application, which has a TreeView, and data is displayed there using a model. Let me present first the code, and describe then the difficulties I have.

class MainWindow(QtGui.QMainWindow):

def __init__(self):

QtGui.QMainWindow.__init__(self)

self.ui = mainwindow.Ui_uiMainWindow()

self.ui.setupUi(self)

self.root = Node('root')

self.childNode = ChildNode('child node', self.root)

self.childNode2 = ChildNode('child node2', self.root)

self._model = PreferencesModel(self.root, self)

self.ui.uiTree.setModel(self._model)

self._propEditor = PropertiesEditor(self)

self.ui.layoutMain.addWidget(self._propEditor)

self._propEditor.setModel(self._model)

self.ui.uiSave.clicked.connect(self.savePreferences)

QtCore.QObject.connect(self.ui.uiTree.selectionModel(),

QtCore.SIGNAL("currentChanged(QModelIndex, QModelIndex)"),

self._propEditor.setSelection)

def savePreferences(self):

pass

What I would like to do is to read all the attributes from childNode and childNode2 for example, and save them into a json or xml file in the savePreferences method. However, I don't know if I should read (or write) the values using self.childNode.attribute or using self._model.

相关阅读:
Top