[PyQt] data from QTreeView

Milan Hemžal milan at 3trees.cz
Sun Dec 14 10:23:30 GMT 2008


hi, 
( i still learned PyQt)

i fill tree object:

        model = QtGui.QStandardItemModel(0, 2, self)        
        model.setHeaderData(0, QtCore.Qt.Horizontal, QtCore.QVariant("Postava"))
        model.setHeaderData(1, QtCore.Qt.Horizontal, QtCore.QVariant("Jméno"))
        for x in po:
            if x.solo <> None:
                jm= x.solo.prijmeni
            else:
                jm=u"Nezadáno"
            model.insertRow(0)
            model.setData(model.index(0, 0), QtCore.QVariant(x.name))
            model.setData(model.index(0, 1), QtCore.QVariant(jm))
        self.proxyModel.setSourceModel(model)

signal in __init__
	...
	self.connect(self.tree_postavy,QtCore.SIGNAL("activated ( const QModelIndex & )"),self.SetPostava)
	...

and method:

    def SetPostava(self,n):        
	# n == index
        mo=self.tree_postavy.model()	
	# next row is depand of column, where user click ,
	# but i need data from first column 
        print QtCore.QVariant.toString((mo.data(n,0)))
	# this is as same
	print QtCore.QVariant.toString((mo.data(n)))

do you any idea, how to get allways data from first column?

Thanks, Milan




More information about the PyQt mailing list