×
Namespaces

Variants
Actions
Revision as of 13:24, 12 September 2009 by fasttrack (Talk | contribs)

Archived:How to use QStackedLayout

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}


Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Article
Keywords: QStackedLayout
Created: (12 Jan 2009)
Last edited: fasttrack (12 Sep 2009)


Overview

This code snippet demonstrates how to use stacked layout in Qt for S60.The QStackedLayout class provides a stack of widgets where only one widget is visible at a time.

Preconditions

Various Function

  • This property determines the way visibility of child widgets are handled.
stackedLayout->setStackingMode(QStackedLayout::StackAll);

Laayout.PNG

Source File

#include "stacked.h"
 
stacked::stacked(QWidget *parent)
: QWidget(parent)
{
firstPageWidget = new QWidget(this);
secondPageWidget = new QWidget(this);
thirdPageWidget = new QWidget(this);
label1 = new QLabel("page1",this);
label2 = new QLabel("page2",this);
label3 = new QLabel("page3",this);
Layout1 = new QVBoxLayout(this);
Layout2 = new QVBoxLayout(this);
Layout3 = new QVBoxLayout(this);
Layout1->addWidget(label1);
Layout2->addWidget(label2);
Layout3->addWidget(label3);
firstPageWidget ->setLayout(Layout1);
secondPageWidget ->setLayout(Layout2);
thirdPageWidget ->setLayout(Layout3);
stackedLayout = new QStackedLayout;
stackedLayout->addWidget(firstPageWidget);
stackedLayout->addWidget(secondPageWidget);
stackedLayout->addWidget(thirdPageWidget);
 
mainLayout = new QVBoxLayout;
pageComboBox = new QComboBox;
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, SIGNAL(activated(int)),stackedLayout, SLOT(setCurrentIndex(int)));
mainLayout->addWidget(pageComboBox);
mainLayout->addLayout(stackedLayout);
setLayout(mainLayout);
 
}
 
stacked::~stacked()
{
// No need to delete any object that has a parent which is properly deleted.
 
}

Header file

#ifndef STACKED_H
#define STACKED_H
#include <QLabel>
#include <QtGui/QWidget>
#include "ui_stacked.h"
#include <QVBoxLayout>
#include <QStackedLayout>
#include <QComboBox>
class stacked : public QWidget
{
Q_OBJECT
 
public:
stacked(QWidget *parent = 0);
~stacked();
 
private:
QLabel* label1;
QLabel* label2;
QLabel* label3;
QWidget* firstPageWidget;
QWidget* secondPageWidget;
QWidget* thirdPageWidget;
QComboBox* pageComboBox;
QStackedLayout* stackedLayout;
QVBoxLayout* mainLayout;
QVBoxLayout* Layout1;
QVBoxLayout* Layout2;
QVBoxLayout* Layout3;
 
};
 
#endif // STACKED_H

Discription

  • In this example three windows are created and they are arranged in a stack. However only one window at a time is visible. A combobox is used to control the display. By changing the value in combobox, the visible window can also be changed.

Screenshots

Stacked1.jpg

Stacked2.jpg

123 page views in the last 30 days.
×