[PyQt] programatically select item in QListView

supik supd at wo.cz
Mon Apr 28 21:50:41 BST 2014

Hi everyone ..

I'm trying show two relational data in two separate QlistView. I'm not 
sure if this is best way, but my program workt fine with this QListView.

Now I want - after fill model with data and show dialog - the first item 
in first listview to be "selected" .

I was read lot of qt stuff, stacowerflow discussions, but still have no 
idea how to do it

class imgmtui( QtGui.QDialog ):
     def __init__(self,  Parent=None):
         self.config = Parent.config
         super(imgmtui,  self).__init__()
         try :
             import magic
             self.magic_imported = True
         except :
             self.magic_imported = False

         self.pathmodel = QtGui.QStandardItemModel()
         self.imagemodel = QtGui.QStandardItemModel()

         for pathname, pathdata in self.config.pathdb.iteritems() :
             pathitem = QtGui.QStandardItem( pathdata['path']
             pathitem.setEditable( False )
             self.pathmodel.appendRow( pathitem )

        self.ui.listView_paths.setModel( self.pathmodel )

so .. and now to do selection... my attempts crash on various errors, 
for example
     self.ui.listView_paths.selectionModel().select(0)  --- crashes 
selectionModel() is nulltype
and I have no idea, how to initialize this ... Also, my English is not 
perfect, and understanding tons of qt - related names an relation 
between them is very difficult for qt newbie as me ..

Can you help me with this problem ?

More information about the PyQt mailing list