Qt-interest Archive, January 2007
Qt4 : QListView : programmatically selecting an item
Message 1 in thread
Hi,
With Qt4, I'm using a QListView, displaying a QStringListModel.
Once the model has been set to the view, I want to programmatically select
one of the displayed items, but I didn't find any methods like
'setCurrentItem' or 'selectItem'...
How can I do that ?
Thanks for your help,
Jerome
--
[ signature omitted ]
Message 2 in thread
Jerome Conus wrote:
> Hi,
>
> With Qt4, I'm using a QListView, displaying a QStringListModel.
>
> Once the model has been set to the view, I want to programmatically select
> one of the displayed items, but I didn't find any methods like
> 'setCurrentItem' or 'selectItem'...
>
> How can I do that ?
> Thanks for your help,
> Jerome
>
>
There's QAbstractItemView::setCurrentIndex. You will need to get a
QModelIndex pointing to the model entry you want to be selected. With a
QStringListModel, this should be as easy as model->index(row, 0), where
row is the position of the string in the string list.
hth
M
--
[ signature omitted ]
Message 3 in thread
Great ! Thanks for your help !
Jerome
"Martin" <martin.umgeher@xxxxxxxxxxx> a écrit dans le message de news:
ep7mak$9iu$1@xxxxxxxxxxxxxxxxxxxxx
> Jerome Conus wrote:
>> Hi,
>>
>> With Qt4, I'm using a QListView, displaying a QStringListModel.
>>
>> Once the model has been set to the view, I want to programmatically
>> select
>> one of the displayed items, but I didn't find any methods like
>> 'setCurrentItem' or 'selectItem'...
>>
>> How can I do that ?
>> Thanks for your help,
>> Jerome
>>
>>
>
> There's QAbstractItemView::setCurrentIndex. You will need to get a
> QModelIndex pointing to the model entry you want to be selected. With a
> QStringListModel, this should be as easy as model->index(row, 0), where
> row is the position of the string in the string list.
>
> hth
> M
--
[ signature omitted ]
Message 4 in thread
Selections are outsorced to QItemSelectionModel; see
QAbstractItemView::selectionModel(). BTW, this is a FAQ; you may want to
save time by searching the archives of this list...
Martin
--
[ signature omitted ]