×
Namespaces

Variants
Actions

How to use QProgressBar in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: QProgressBar,QSpinBox
Created: james1980 (04 Jan 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This code snippet demonstrates how to use a QProgressBar in Qt.

Various Functions

  • This display the current completed percentage in progress bar.
bar->setVisible(1);
Qtprogress2.jpg
  • This property is used to invert the direction of the progress in progress bar.
bar->setInvertedAppearance(1);
SpinInvert.JPG
  • This function is used for the orientation of progress bar.
bar->setOrientation(Qt::vertical);

Progressbar1.JPG

Header file

#ifndef PROGRESSBAR_H
#define PROGRESSBAR_H
 
#include <QtGui/QWidget>
#include "ui_progressbar.h"
#include <QProgressBar>
#include <QSpinBox>
#include <QVBoxLayout>
 
class progressbar : public QWidget
{
Q_OBJECT
 
public:
progressbar(QWidget *parent = 0);
~progressbar();
 
private:
QWidget* win;
QVBoxLayout* layout;
QProgressBar* bar;
QSpinBox* spin;
};
 
#endif // PROGRESSBAR_H


Source file

#include "progressbar.h"
 
progressbar::progressbar(QWidget *parent)
: QWidget(parent)
{
win = new QWidget(this);
win->setWindowTitle(("LCD Number"),this);
layout = new QVBoxLayout(this);
bar = new QProgressBar(this);
spin = new QSpinBox(this);
spin->setMaximum(99);
spin->setMinimum(0);
bar->resize(200,25);
bar->setOrientation(Qt::Horizontal);//Orientation can also be vertical
bar->setRange(0,99);
connect(spin, SIGNAL(valueChanged(int)), bar, SLOT(setValue(int)));
layout->addWidget(spin,Qt::AlignCenter);
 
layout->addWidget(bar,Qt::AlignCenter);
win->setLayout(layout);
win->showMaximized();
}
 
progressbar::~progressbar()
{
// No need to delete any object that has a parent which is properly deleted.
}


PostConditions

  • Here as you change the value of the spinbox progress bar will also changed.

Qtprogress1.jpg

  • Screen shot at 40% progress

Qtprogress2.jpg

Example

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

×