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

Tuesday, March 24th 2009, 5:36pm

How to iterate among the QListWidgetItems of a QListWidget ?

I have an horizontal QListView that shows multiple thumbnails.
For different reasons, i must be able to move the selection from the currently selected item to the one immediately to his left or right.

In other words, i must find the previous or next QListViewItem in relation to the currently selected one.

Source code

1
ui->listWidget->currentItem()->nextItem()->selected(true);	// This of course, doesn't work !!!!


Thanks !

2

Tuesday, March 24th 2009, 5:48pm

Source code

1
2
3
foreach(QListWidgetItem *selectedItem, ui->listWidget->selectedItems()) {
    // do something with selectedItem
}
Mandriva Linux release 2009.0 (Official) for i586
Kernel 2.6.27.10-desktop-1mnb on a Dual-processor i686

3

Tuesday, March 24th 2009, 8:01pm

Source code

1
2
3
foreach(QListWidgetItem *selectedItem, ui->listWidget->selectedItems()) {
    // do something with selectedItem
}
I am working in single selection mode !

I do not which to iterate among the selected items...
I want to iterate amont the items in the list itself.

4

Tuesday, March 24th 2009, 8:41pm

Source code

1
2
3
4
// select next
ui->listWidget->setCurrentRow(ui->listWidget->currentRow() + 1, QItemSelectionModel::SelectCurrent);
// select previous
ui->listWidget->setCurrentRow(ui->listWidget->currentRow() - 1, QItemSelectionModel::SelectCurrent);
Mandriva Linux release 2009.0 (Official) for i586
Kernel 2.6.27.10-desktop-1mnb on a Dual-processor i686