×
Namespaces

Variants
Actions

Archived:How to use QListWidget and QListWidgetItem

From Nokia Developer 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.

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.

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
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QListWidget,QListItemWidget
Created: mind_freak (14 Mar 2009)
Last edited: hamishwillee (11 Oct 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

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