Namespaces
Variants
Actions

Archived:How to select multiple items with QListWidget

Jump to: navigation, search
Archived.png
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.

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
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.

Multiselection.png

Download the example for Belle: File:ListWidgetMulti.zip

This page was last modified on 11 October 2012, at 04:14.
377 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved