[PyQt] QTreeView and QDataWidgetMapper

Nicolas Girard nicolas.girard at nerim.net
Mon Sep 17 16:59:01 BST 2007


Hi again,

in the following example I would expect the lineEdit contents to be refreshed 
each time the treeview's selection changes ; unfortunately it doesn't work. I 
tried to follow the Qt docs but I'm probably missing something... but what ?

Cheers,
Nicolas

===
#!/usr/bin/python
from PyQt4 import QtCore,QtGui
import sys

class Window(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.tree = QtGui.QTreeView(self)
        self.lineEdit = QtGui.QLineEdit(self)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.lineEdit)
        layout.addWidget(self.tree)
        self.setLayout(layout)
    def setModel(self,model):
        self.tree.setModel(model)
        self.tree.resize(640, 480)
        self.dwm = QtGui.QDataWidgetMapper(self)
        self.dwm.setModel(model)
        self.dwm.addMapping(self.lineEdit, 0)
        self.connect(self.tree.selectionModel(), 
            QtCore.SIGNAL("currentRowChanged(QModelIndex,QModelIndex)"),
            self.dwm, QtCore.SLOT("setCurrentModelIndex(QModelIndex)"))

if __name__=="__main__":
    app=QtGui.QApplication(sys.argv)
    window=Window()
    model = QtGui.QDirModel()
    window.setModel(model)
    window.show()
    sys.exit(app.exec_())


More information about the PyQt mailing list