Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:How to select multiple items with QListWidget

From Wiki
Jump to: navigation, search

Archived.pngArchived: 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.

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 ExampleTested with
Devices(s): Nokia C7-00 with Belle Firmware
Nokia Belle
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:

This page was last modified on 11 October 2012, at 01:14.
238 page views in the last 30 days.