×
Namespaces

Variants
Actions
Revision as of 09:30, 3 September 2009 by croozeus (Talk | contribs)

Archived:Getting image from list in Qt

From Nokia Developer Wiki
Jump to: navigation, search


Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: QListWidget,QIcon,QPixmap
Created: (19 Jul 2009)
Last edited: croozeus (03 Sep 2009)

Overview

This is a 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.

Name of class used:

QListWidget-Provides an item-based list widget

QPixmap-off-screen image representation that can be used as a paint device.

Preconditions

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

  • Download an example project from here: Screen.zip
167 page views in the last 30 days.
×