×
Namespaces

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

Archived:How to use QWidget

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: QWidget
Created: (17 Jan 2008)
Last edited: fasttrack (12 Sep 2009)
{{{width}}}

Contents

Introduction

The QWidget class is the base class of all user interface objects.It receives mouse, keyboard and other events from the window system, and paints a representation of itself on the screen.Every widget is rectangular, and are sorted in a Z-order.

A Widget is called a window if it is not embedded in a parent widget. Non window widgets are used as a child widgets. Most of the Widgets in Qt are used as a child widgets.

When a widgets is used as a container to group a number of child widgets, it is known as a composite widget.

Download


Various Function

  • The size of a QWidget can be set or modified with the method QWidget::resize().
QWidget window;
window.resize(100,50);


  • Qt provide a system of layout to organize the size and position of children widgets. Here is an example using QVBoxLayout to align two buttons vertically:
QVBoxLayout *layout=new QVBoxLayout();
layout->addWidget(new QPushButton("Hello"));
layout->addWidget(new QPushButton("Bye Bye"));
window.setLayout(layout);
Widget1.JPG
  • To make Widget visible we have to use QWidget::show()
window->show();

Code Snippet

#include <QApplication>
#include <QPushButton>
#include <QVBoxLayout>
 
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(100,50);
QVBoxLayout *layout=new QVBoxLayout();
layout->addWidget(new QPushButton("Hello"));
layout->addWidget(new QPushButton("Bye Bye"));
window.setLayout(layout);
window.show();
return app.exec();
}
59 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×