×
Namespaces

Variants
Actions

Archived:How to make a customized widget in Qt

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: 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.

This (archived) article shows the procedure for customising aQWidget.

Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: Customized Widget
Created: james1980 (30 Dec 2008)
Last edited: hamishwillee (11 Oct 2012)

Contents

Introduction

Create a new Qt project of type GUI widget following the procedure given Getting started with Qt.

Then replace the three files named main.cpp, customwidget.h and customwidget.cpp with the code given below.

Main.cpp

#include <QApplication>
 
#include "customwidget.h"
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
CustomWidget w;
w.show();
return a.exec();
}


customwidget.h

#ifndef CUSTOMWIDGET_H
#define CUSTOMWIDGET_H
 
#include <QWidget>
 
class CustomWidget : public QWidget
{
Q_OBJECT
 
public:
CustomWidget(QWidget *parent = 0);
};
 
#endif // CUSTOMWIDGET_H


customwidget.cpp

#include <QPushButton>
#include <QVBoxLayout>
#include <QCoreApplication>
 
#include "customwidget.h"
 
CustomWidget::CustomWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
 
// This button show the top level widget in a normal size
QPushButton* normalSizeButton = new QPushButton("Normal size");
QObject::connect(normalSizeButton, SIGNAL(clicked()), this, SLOT(showNormal()));
layout->addWidget(normalSizeButton);
 
// This button maximize the widget size
QPushButton* maximzeButton = new QPushButton("Maximize");
QObject::connect(maximzeButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
layout->addWidget(maximzeButton);
 
// This button exit the application
QPushButton* exitButton = new QPushButton("Exit");
QObject::connect(exitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
layout->addWidget(exitButton);
}

Output Image

Customnormal.jpg

This page was last modified on 11 October 2012, at 01:14.
39 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.

×