×
Namespaces

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

How to use QVBoxLayout and QHBoxLayout in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Symbian
Article
Keywords: QVBoxLayout,QHBoxLayout
Created: (27 Dec 2008)
Last edited: fasttrack (12 Sep 2009)
{{{width}}}


Contents

Introduction

Basically Qt supports many basic layouts in which you can arrange your widgets for display on the screen. It supports the following layout types.

  1. Vertical layout
  2. Horizontal layout
  3. Grid layout
  4. Form layout

This article shows the use of the first two layouts, Vertical and Horizontal

How to use QVBoxLayout

Source code

#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
 
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* win = new QWidget();
QVBoxLayout* layout = new QVBoxLayout(win);
QPushButton* but1 = new QPushButton("Horizontal");
but1->resize(70,20);
layout->addWidget(but1);
QPushButton* but2 = new QPushButton("Vertical");
but2->resize(70,20);
layout->addWidget(but2);
 
win->show();
 
return app.exec();
}

Screen Shot

Vertical.jpg


How to use QHBoxLayout

Source code

#include <QApplication>
#include <QPushButton>
#include <QHBoxLayout>
 
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* win = new QWidget();
QHBoxLayout* layout = new QHBoxLayout(win);
QPushButton* but1 = new QPushButton("Horizontal");
but1->resize(70,20);
layout->addWidget(but1);
QPushButton* but2 = new QPushButton("Vertical");
but2->resize(70,20);
layout->addWidget(but2);
win->show();
 
return app.exec();
}

Screen Shot

Horizontal.jpg

223 page views in the last 30 days.
×