6.0.0-rc4Source

QProgressBar Class

The QProgressBar class shows how far an operation has come. More…

Header#include <QProgressBar>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Functions

QProgressBar(QWidget *parent = nullptr)
~QProgressBar()
intminimum() const
voidsetMinimum(int minimum)
intmaximum() const
voidsetMaximum(int maximum)
voidsetRange(int minimum, int maximum)
intvalue() const
boolisTextVisible() const
voidsetTextVisible(bool visible)
QStringformat() const
voidsetFormat(const QString &format)
QStringtext() const

Reimplemented Public Functions

Public Slots

voidsetValue(int value)
voidreset()

Signals

voidvalueChanged(int value)

Reimplemented Protected Functions

voidpaintEvent(QPaintEvent *event)
voidchangeEvent(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.

QProgressBar in the light color scheme

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

[explicit] QProgressBar::QProgressBar(QWidget *parent = nullptr)

Constructs a progress bar with the range 0 to 100 and no value, with the given parent.

[override] QProgressBar::~QProgressBar()

Destroys the progress bar.

[override, protected] 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().

[override] QSize QProgressBar::minimumSizeHint() const

Reimplements QWidget::minimumSizeHint().

[override, protected] void QProgressBar::paintEvent(QPaintEvent *event)

Reimplements QWidget::paintEvent().

[slot] 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.

See also format() and text().

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().

[slot] 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().

[override] 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().

[signal] void QProgressBar::valueChanged(int value)

This signal is emitted when the value changes to value.