Archived:How to select multiple items with QListWidget
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
The QListWidget class provides an item-based list widget that contains a number of QListWidgetItems. This code snippet shows how we can touch and select multiple items using this list widget.
Article Metadata
Code Example
Source file: Media:ListWidgetMulti.zip
Tested with
Devices(s): Nokia C7-00 with Belle Firmware
Article
Created: mahbub_s60
(20 Dec 2011)
Last edited: hamishwillee
(11 Oct 2012)
What needs to be done to enable multiple selection
The selectionMode() of a list widget determines how many of the items in the list can be selected at the same time, and whether complex selections of items can be created. This can be set with the setSelectionMode() function.
setSelectionMode(QAbstractItemView::MultiSelection );
We associate itemClicked signal with corresponding slot.
connect(this, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(HandleItem()));
When an item is clicked then the HandleItem() slot is called. HandleItem() looks like this:
void ContentTab::HandleItem()
{
currentItem()->setSelected (!currentItem()->isSelected());
setCurrentRow(currentRow(), QItemSelectionModel::Toggle );
}
Sample Example
Sample code can be downloaded from the following zip file, It was tested with C7 Belle SW.
Download the example for Belle: File:ListWidgetMulti.zip



(no comments yet)