×
Namespaces

Variants
Actions

Archived:Getting image from list in Qt

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 code examples shows how to create an image viewing widget. On clicking the items in list we can view the full size image. Image icon are set in the list widget and the same path for the image icon is used for getting the image from that specific directory.

Article Metadata
Code Example
Source file: Media:Screen.zip
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: QListWidget,QIcon,QPixmap
Created: mind_freak (19 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)

Names of classes used are:

  • QListWidget - Provides an item-based list widget
  • QPixmap - off-screen image representation that can be used as a paint device.

Contents

Source Code

#include "database.h"
#include "ui_database.h"
 
database::database(QWidget *parent)
: QWidget(parent)
{
list=new QListWidget(this);
list->setIconSize(QSize(30,30));
 
lbl=new QLabel(this);
lbl->setMinimumSize(240, 160);
item1=new QListWidgetItem(QIcon("D://Blue hills.PNG"),"BlueHills",list,this);
item2=new QListWidgetItem(QIcon("D://Sunset.PNG"),"Sunset",list,this);
item3=new QListWidgetItem(QIcon("D://Water lilies.PNG"),"Water lilies",list,this);
connect(list,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(myitem(QListWidgetItem*)));
llb=new QLabel("Image will be displayed here");
llb->setAlignment(Qt::AlignCenter);
lay=new QGridLayout(this);
lay->addWidget(list,0,0);
lay->addWidget(llb,0,1);
lay->addWidget(lbl,0,1);
setLayout(lay);
showMaximized();
setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
}
 
database::~database()
{
 
}
void database::myitem(QListWidgetItem *my)
{
 
QPixmap pix;
llb->hide();
QIcon ico;
ico=my->icon();
pix=ico.pixmap(QSize(400,400),QIcon::Selected,QIcon::On);
lbl->setPixmap(pix.scaled(pix.size(),Qt::KeepAspectRatio,Qt::SmoothTransformation));
 
 
}

Emulator Screenshot

Listwid.jpg


Creator IDE look

Sunimage1.JPG

Example

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