You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, November 24th 2008, 3:34am

QListWIdget:- Multiple selection

Hi All,

I want to create one application using QLIstWidget but I am facing one problem in that :(

I want to do the multiple selection (using control + mouse left click)so that I can copy different selected items in the one QLIstWidget to another QListWidget .
For that changed the selection property.

Source code

1
setSelectionMode(QAbstractItemView::ExtendedSelection);


But how can I get multiple indexes ???? I mean is there any way of getting list of selected indexes??


Thanks in advance.

2

Monday, November 24th 2008, 11:06am

QList<QListWidgetItem *> selectedItems () const

3

Friday, November 28th 2008, 7:37am

Thanks four your reply Nicholas.

I got the solution this is for those who may face this problem.

Source code

1
2
3
4
5
6
7
8
9
QStandardItemModel* modelFunName = new QStandardItemModel(1000, 1, this); //let's hardcode it for a while
QItemSelectionModel* selModelName = new QItemSelectionModel(modelFunName);
QListView *listViewName =  new QListView();
listViewName->setSelectionModel(selModelName); 
QModelIndexList modelList;
modelList << selModelName->selectedIndexes();for(int i =0 ; i < modelList.size() ; i++) 
{
//modelList[i].row();  this will give the list of selected indexes.
}