Namespaces
Variants
Actions

How to use QListWidget and QListWidgetItem

Jump to: navigation, search

This example shows how to create simple lists using a QListWidget populated withQListWidgetItems. QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items.

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

Tested with
Devices(s): Qt Creator IDE & S60 Emulator

Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition

Platform Security
Signing Required: Self-Signed
Capabilities: None

Article
Keywords: QListWidget,QListItemWidget
Created: mind_freak (14 Mar 2009)
Last edited: hamishwillee (05 Mar 2012)

Contents

Various Function

  • If this property is true, sorting is enabled for the list; if the property is false, sorting is not enabled. The default value is false.
 listWidget->setSortingEnabled(true);

Source Code

#include <QApplication>
#include <QWidget>
#include <QHBoxLayout>
#include <QListWidget>
#include <QListWidgetItem>
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
 
QListWidget *listWidget = new QListWidget();
listWidget->setSortingEnabled(true);
listWidget->addItem(new QListWidgetItem("Oak"));
listWidget->addItem(new QListWidgetItem("Banana"));
listWidget->addItem(new QListWidgetItem("Apple"));
listWidget->addItem(new QListWidgetItem("Orange"));
listWidget->addItem(new QListWidgetItem("Grapes"));
listWidget->addItem(new QListWidgetItem("Jayesh"));
listWidget->addItem(new QListWidgetItem("Pineapple"));
listWidget->addItem(new QListWidgetItem("GROUNDNUT"));
listWidget->addItem(new QListWidgetItem("Sugarcane"));
listWidget->addItem(new QListWidgetItem("Coconut"));
listWidget->addItem(new QListWidgetItem("Remote"));
listWidget->addItem(new QListWidgetItem("Mango"));
 
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(listWidget);
 
QMainWindow w;
w.setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
w.setCentralWidget(listWidget);
w.showMaximized();
 
return a.exec();
}


Screnshot

Listwidget001.jpg


Icon listview

list=new QListWidget();
item1=new QListWidgetItem(QIcon("D:\\Blue hills.PNG"),"BlueHills",list);
item2=new QListWidgetItem(QIcon("D:\\Sunset.PNG"),"Sunset",list);
item3=new QListWidgetItem(QIcon("D:\\Water lilies.PNG"),"Water lilies",list);
item4=new QListWidgetItem(QIcon("D:\\Winter.PNG"),"Winter",list);

screen shot

Ico.JPG

Comments

Reviewer-approved.png
13 Sep
2009
Article Review by deepikagohil (20090913)

The article presents step-by-step implementation to create list in a list widget in Qt for Symbian. Short guide, code snippest and screen-shot all related to the application are included in the article. It gives primary information about how to use QListWidget and QListWidgetItam APIs.

Creating a list in a widget is a primary thing and generally beginners may find it difficult. The article explains it a simple manner. The article can be useful to the beginners who are working on widgets.


Naufalahad - Reg: Icon View

Hi all,

I am having a problem with QIcon list view,where in the above screen example they have added the image to the list widget,but when i declare an item1 in that coding i am not able to get the solution.

list=new QListWidget();
item1=new QListWidgetItem(QIcon("D:\\Blue hills.PNG"),"BlueHills",list);
item2=new QListWidgetItem(QIcon("D:\\Sunset.PNG"),"Sunset",list);
item3=new QListWidgetItem(QIcon("D:\\Water lilies.PNG"),"Water lilies",list);
item4=new QListWidgetItem(QIcon("D:\\Winter.PNG"),"Winter",list);

I am getting the error as :

error: incomplete universal character name \U
Thanks and regards if any one find me a solution!!!!

naufalahad 15:17, 10 November 2011 (EET)

Hamishwillee - @Naufalahad - try forums

Hi Naufalahad

This article was written by Mind_freak a few years ago, and he might not be watching it. Suggest you either message directly through private messaging (hover over his name in the ArticleMetaData on top right of page) or ask question in the forums.

Looking at your error I'd say its probably nothing to do with this segment of code. This might be caused by an ill formed unicode character somewhere.

regards

Hamish

hamishwillee 05:48, 17 November 2011 (EET)

This page was last modified on 5 March 2012, at 06:48.
807 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 2012 All rights reserved