Namespaces
Variants
Actions

Archived:How to use a list widget with a scroll area in Qt

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

Tested with
Devices(s): S60 Emulator

Compatibility
Platform(s): S60 5th Edition, Qt 4.5

Article
Keywords: QScrollArea
Created: mind_freak (24 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

In this article we will learn how can we implement scroll bar in List Widget This code snippet and attached example shows the implementation of list widget with a scroll area. Using this we can scroll the list view horizontally as well as vertically.

A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed.

In this example following key classes are used:

Source Code for list widget in QScrollArea

#include "widget.h"
 
 
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
list=new QListWidget();
lay=new QHBoxLayout();
QSizeGrip *gr=new QSizeGrip(list);//to resize the widget
scroll=new QScrollArea();
 
scroll->setWidget(list);
scroll->setAlignment(Qt::AlignLeft);
// scroll->setWidgetResizable(true);
scroll->setBackgroundRole(QPalette::Dark);// set background of scroll Area
//win=new QWidget();
item1=new QListWidgetItem("BlueHills",list);//adding items to list
item2=new QListWidgetItem("Sunset",list);
item3=new QListWidgetItem("Water lilies",list);
item4=new QListWidgetItem("Himaliya is a good place",list);
item5=new QListWidgetItem("Ooty",list);
item6=new QListWidgetItem("Hero Honda",list);
item7=new QListWidgetItem("www.google.com",list);
item8=new QListWidgetItem("orkut.com",list);
item9=new QListWidgetItem("sunrise",list);
item10=new QListWidgetItem("OVI",list);
item11=new QListWidgetItem("Nokia N97",list);
item12=new QListWidgetItem("forum.nokia.com",list);
item13=new QListWidgetItem("wellcome to Qt",list);
item14=new QListWidgetItem("Qt rocks for s60",list);
item15=new QListWidgetItem("Symbian c++",list);
item16=new QListWidgetItem("5800 Xpress Music",list);
item17=new QListWidgetItem("My best Phone",list);
item18=new QListWidgetItem("I like N97",list);
item19=new QListWidgetItem("Go for 5800",list);
item20=new QListWidgetItem("America",list);
// lay->addWidget(list);
lay->addWidget(scroll);
 
setLayout(lay);//setting layout
showMaximized();
}
 
Widget::~Widget()
{
}

Screenshot (using Symbian emulator)

Scroll01.jpg


Source for Image in QScrollArea

#include "widget.h"
 
 
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QLabel *imageLabel = new QLabel(this);
QImage image("E:\\flower.png",this);
lay=new QHBoxLayout(this);
imageLabel->setPixmap(QPixmap::fromImage(image));
 
scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(1);
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
lay->addWidget(scrollArea);
setLayout(lay);
}
 
Widget::~Widget()
{
}

Screenshot

Scrollarea2.JPG

To do

  • Zooming image with hekp of scrollArea
This page was last modified on 11 October 2012, at 04:14.
759 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