QProgressBar Class
The QProgressBar class shows how far an operation has come. More…
| Header | #include <QProgressBar> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
List of all members, including inherited members
Public Functions
| QProgressBar(QWidget *parent = nullptr) | |
| ~QProgressBar() | |
| int | minimum() const |
| void | setMinimum(int minimum) |
| int | maximum() const |
| void | setMaximum(int maximum) |
| void | setRange(int minimum, int maximum) |
| int | value() const |
| bool | isTextVisible() const |
| void | setTextVisible(bool visible) |
| QString | format() const |
| void | setFormat(const QString &format) |
| QString | text() const |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Public Slots
Signals
| void | valueChanged(int value) |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | changeEvent(QEvent *event) |
Detailed Description
A progress bar fills from the left as its value goes from the minimum to the maximum, and shows the progress as a text on the bar. The text comes from format(), in which %p stands for the percentage, %v for the value and %m for the number of steps:
QProgressBar *bar = new QProgressBar(window);
bar->setRange(0, 200);
bar->setFormat("%v of %m");
bar->setValue(50);
Progress bars: without a value, at 35 percent, complete, with a format, without text, and disabled.

See also QSlider.
Differences from Qt
The bar is horizontal and grows from the left: there is no setOrientation() and no setInvertedAppearance(). There is no busy indicator for a range of 0 to 0, which shows an empty bar, and no setTextDirection(). The text is always centered.
Member Function Documentation
QProgressBar::QProgressBar(QWidget *parent = nullptr)
Constructs a progress bar with the range 0 to 100 and no value, with the given parent.
QProgressBar::~QProgressBar()
Destroys the progress bar.
void QProgressBar::changeEvent(QEvent *event)
Reimplements QWidget::changeEvent().
QString QProgressBar::format() const
Returns the format of the text, %p% by default.
See also setFormat().
bool QProgressBar::isTextVisible() const
Returns whether the text is shown on the bar. The default is true.
See also setTextVisible().
int QProgressBar::maximum() const
Returns the value that stands for completion, 100 by default.
See also setMaximum().
int QProgressBar::minimum() const
Returns the value that stands for no progress, 0 by default.
See also setMinimum().
QSize QProgressBar::minimumSizeHint() const
Reimplements QWidget::minimumSizeHint().
void QProgressBar::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
void QProgressBar::reset()
Resets the progress bar: the value goes to one less than the minimum, which shows an empty bar and no text.
See also setValue().
void QProgressBar::setFormat(const QString &format)
Sets the format of the text to format: %p is replaced by the percentage, %v by the value and %m by the number of steps from the minimum to the maximum.
void QProgressBar::setMaximum(int maximum)
Sets the maximum to maximum. The minimum falls to the same if it was larger.
See also maximum().
void QProgressBar::setMinimum(int minimum)
Sets the minimum to minimum. The maximum grows to the same if it was smaller.
See also minimum().
void QProgressBar::setRange(int minimum, int maximum)
Sets the range to minimum to maximum. If maximum is less than minimum, it is made equal. A value that falls outside the range is reset.
See also reset().
void QProgressBar::setTextVisible(bool visible)
Sets whether the text is shown to visible.
See also isTextVisible().
void QProgressBar::setValue(int value)
Sets the value to value. It is ignored if it is outside the range. Emits valueChanged() if the value changes.
See also value().
QSize QProgressBar::sizeHint() const
Reimplements QWidget::sizeHint().
QString QProgressBar::text() const
Returns the text that is shown on the bar: the format with its codes replaced. It is empty if there is no value.
See also format().
int QProgressBar::value() const
Returns the value, one less than the minimum if there is none.
See also setValue() and reset().
void QProgressBar::valueChanged(int value)
This signal is emitted when the value changes to value.