I did a little class to show a QProgressBar:
ProgressDialog.h:
/*
* ProgressDialog.h
*
* Created on: 26/08/2011
* Author: Sergio Madrazo Giménez
*/
#include <QDialog>
#include <QProgressBar>
#include <QHBoxLayout>
#ifndef PROGRESSDIALOG_H_
#define PROGRESSDIALOG_H_
class ProgressDialog
: public QDialog{
Q_OBJECT
public:
ProgressDialog
(QWidget *parent
=0,
int t
=0);
virtual ~ProgressDialog();
private:
int total;
public slots:
void setNuber(int num);
};
#endif /* PROGRESSDIALOG_H_ */
/*
* ProgressDialog.h
*
* Created on: 26/08/2011
* Author: Sergio Madrazo Giménez
*/
#include <QDialog>
#include <QProgressBar>
#include <QHBoxLayout>
#ifndef PROGRESSDIALOG_H_
#define PROGRESSDIALOG_H_
class ProgressDialog : public QDialog{
Q_OBJECT
public:
ProgressDialog(QWidget *parent=0, int t=0);
virtual ~ProgressDialog();
private:
int total;
QProgressBar *progressBar;
public slots:
void setNuber(int num);
};
#endif /* PROGRESSDIALOG_H_ */
To copy to clipboard, switch view to plain text mode
ProgressDialog.cpp
/*
* ProgressDialog.cpp
*
* Created on: 26/08/2011
* Author: Sergio Madrazo Giménez
*/
#include <QtGui>
#include "ProgressDialog.h"
ProgressDialog
::ProgressDialog(QWidget *parent,
int t
){
total = t;
progressBar->setRange(0,100);
progressBar->setValue(50);
progressBar->setVisible(true);
progressBar->setMaximumSize(500,30);
progressBar->setMinimumSize(200,30);
}
ProgressDialog::~ProgressDialog() {
delete progressBar;
}
/********************************
************ SLOTS *************
********************************/
/*
* This slot changes the value of the progress bar.
* Input: number of items.
* It calculates automatically the percentage
*/
void ProgressDialog::setNuber(int num){
progressBar->setValue((num*100)/total);
}
/*
* ProgressDialog.cpp
*
* Created on: 26/08/2011
* Author: Sergio Madrazo Giménez
*/
#include <QtGui>
#include "ProgressDialog.h"
ProgressDialog::ProgressDialog(QWidget *parent, int t)
: QDialog(parent)
{
total = t;
progressBar = new QProgressBar (parent);
progressBar->setRange(0,100);
progressBar->setValue(50);
progressBar->setVisible(true);
progressBar->setMaximumSize(500,30);
progressBar->setMinimumSize(200,30);
}
ProgressDialog::~ProgressDialog() {
delete progressBar;
}
/********************************
************ SLOTS *************
********************************/
/*
* This slot changes the value of the progress bar.
* Input: number of items.
* It calculates automatically the percentage
*/
void ProgressDialog::setNuber(int num){
progressBar->setValue((num*100)/total);
}
To copy to clipboard, switch view to plain text mode
This class has two paremeters imput:
- QWidget *parent: When you call the constructor you can put it the Widget that you want. If you put 0, the it will open a new window.
- int t: this is the total. For example, if you have 5 things to do, it will be 5. Every time you finish one thing you call the method setImage with the number you finished.
Sorry for my poor english!
Bookmarks