[PyQt] data from QTreeView

David Boddie david at boddie.org.uk
Sun Dec 14 21:05:29 GMT 2008

On Sun, 14 Dec 2008 11:23:30 +0100, Milan Hemžal wrote:

>     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)))

This is because the second argument to the model's data() method specifies
the role, not the column number.

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

You need to pass an index with the correct column number to the model's
data() method. One way to do this is to call the index's sibling() method
with the column number you want, then pass this to the model's data()
method. Maybe something like this:

  index = n.sibling(n.row(), 0)
  print QtCore.QVariant.toString(mo.data(index))

Hope this helps,


More information about the PyQt mailing list