How to Create QProgressBar in Qt5 GUI

In this article iam going to show you How to Create QProgressBar in Qt5 GUI.

So a progress bar is used to give the user an indication of the progress of an operation and to reassure them that the application is still running.

The progress bar uses the concept of steps. You set it up by specifying the minimum and maximum possible step values, and it will display

the percentage of steps that have been completed when you later give it the current step value. The percentage is calculated by dividing the

progress (value() – minimum()) divided by maximum() – minimum().

You can specify the minimum and maximum number of steps with setMinimum() and setMaximum. The current number

of steps is set with setValue(). The progress bar can be rewound to the beginning with reset().

 

OK first of all you need to create a New Project in Qt5 Framework, after creating New Project we need to design

our dialog.ui. basically we are going to add a QProgressbar and Horizontal QSilder widget in the design like this .

Qt5 QProgressbar
Qt5 QProgressbar

 

 

So now open your dialog.cpp file and add this code in the constructor, basically we are going to connect

valueChanged() signal of Horizontal Slider with setValue() slot of Progressbar.

 

 

After adding your dialog.cpp will look like this

 

 

 

So now run your complete project and this will be the result

How to Create QProgressBar in Qt5 GUI
How to Create QProgressBar in Qt5 GUI

 

 

OK now in here we have a problem, when your run your project in the first the QProgressbar value is

not set to zero, so for this you need to add this line of code in dialog.cpp constructor.

 

 

So after adding your dialog.cpp will look like this

 

 

Run the complete project and this will be the result

Qt5 QProgressBar
Qt5 QProgressBar

 

 

Also check Qt5 C++ GUI Development Articles in the below links

 

1: Qt5 C++ Introduction And Installation

2: Qt5 C++ First Console Application 

3: Qt5 C++ First GUI Application 

4: Qt5 C++ Signal And Slots Introduction

5: Qt5 C++ Layout Management 

6: Qt5 C++ Creating Qt Style Sheets

7: Qt5 C++ Creating QPushButton

8: How To Create QCheckBox in Qt5

9: Qt5 GUI How To Create QRadioButton

10: Qt5 GUI Development How To Create ComboBox

11: Qt5 C++ GUI Development Creating QListWidget

12: Qt5 C++ GUI Development Creating QMessageBox

13 : Qt5 C++ GUI Creating QMenu And QToolbar

14: Qt5 C++ GUI Development Creating QPrintDialog

15: Qt5 C++ GUI Development Creating QFontDialog

16: Qt5 C++ GUI Development Creating QColorDialog

17: How to Create QFileDialog in Qt5 C++

 

 

 

Also you can watch the complete video for this article 

 

 

Share via
Copy link
Powered by Social Snap