[Qt-interest] How to get selected listitem index in Qt

Andreas Pakulat apaku at gmx.de
Fri Apr 16 11:39:01 CEST 2010


On 16.04.10 09:16:51, Rainer Wiesenfarth wrote:
> 
> (please quote reader-friendly, even given the fact, Outlook does not support
> this)
> 
> From: Ramesh [mailto:ramesh.bs at robosoftin.com] 
> > From: Rainer Wiesenfarth
> > > From: Ramesh
> > > > I am having a QListView which having some items. Now i 
> > > > want to get 
> > > > the index of selected item. i.e. if i select 5th element i 
> > > > should get 5. How i can get this?..
> > > 
> > > QModelIndexList  QAbstractItemView::selectedIndexes () const
> >
> > Ya, I gone through the documentation I had fount this 
> > selectedIndexes (),
> > but selected indexes will give the list, we need to iterate 
> > for getting the modelindex.
> 
> Yes and no. If you allow multiple selection, the list may contain multiple
> items - in fact all selected ones. If you only allow single selection, the
> list may be either empty or contain exactly one item. Thus "iteration" is
> very limited here.

Not necessarily. In tables and tree's with multiple columns you'll still
get a list unless you active single-item-selection (instead of row or
column-selection) even in single-selection mode (as all indexes of the
single selected row are reported). I guess thats one of the reasons that
QItemSelectionModel has two getters for selected row(s) and selected
column(s).

Andreas

-- 
"Life, loathe it or ignore it, you can't like it."
		-- Marvin, "Hitchhiker's Guide to the Galaxy"



More information about the Qt-interest-old mailing list