QProgressBar Class

QProgressBar 提供一个水平或垂直进度条. 更多...

头文件: #include <QProgressBar>
qmake: QT += widgets
基类: QWidget

公有类型

enum Direction { TopToBottom, BottomToTop }

属性

公有函数

QProgressBar(QWidget *parent = Q_NULLPTR)
~QProgressBar()
Qt::Alignment alignment() const
QString format() const
bool invertedAppearance() const
bool isTextVisible() const
int maximum() const
int minimum() const
Qt::Orientation orientation() const
void resetFormat()
void setAlignment(Qt::Alignment alignment)
void setFormat(const QString &format)
void setInvertedAppearance(bool invert)
void setTextDirection(QProgressBar::Direction textDirection)
void setTextVisible(bool visible)
virtual QString text() const
QProgressBar::Direction textDirection() const
int value() const

重新实现的公有函数

virtual QSize minimumSizeHint() const
virtual QSize sizeHint() const

公有槽函数

void reset()
void setMaximum(int maximum)
void setMinimum(int minimum)
void setOrientation(Qt::Orientation)
void setRange(int minimum, int maximum)
void setValue(int value)
  • 19 个公有槽函数继承自 QWidget
  • 1 个公有槽函数继承自 QObject

信号

void valueChanged(int value)

受保护的函数

void initStyleOption(QStyleOptionProgressBar *option) const

重新实现的受保护函数

virtual bool event(QEvent *e)
virtual void paintEvent(QPaintEvent *)
  • 35 个受保护的函数继承自 QWidget
  • 9 个受保护的函数继承自 QObject
  • 1 个受保护的函数继承自 QPaintDevice

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 5 个静态公有成员继承自 QWidget
  • 10 个静态公有成员继承自 QObject
  • 1 个受保护的槽函数继承自 QWidget
  • 2 个受保护的变量继承自 QObject
  • 1 protected type inherited from QPaintDevice

详细描述

QProgressBar 提供一个水平或垂直进度条.

进度条可以向用户显示操作进度, 表示应用程序仍在运行.

进度条使用 步数 概念. 你可以先设置最小和最大步数, 然后再设置当前步数时, 进度条显示已完成步数的百分比. 百分比的计算方式是 (value() - minimum()) / (maximum() - minimum()).

调用 setMinimum() 和 setMaximum设置最小和最大步数. 调用 setValue()设置当前步数. 调用 reset() 重置当前步数为最小步数.

如果最小和最大步数设置为 0, 进度条显示忙碌指示器. 例如, 使用 QNetworkAccessManager 下载大小未知的资源时, 可以显示忙碌指示器.

Screenshot of a Macintosh style progress barA progress bar shown in the Macintosh widget style.
Screenshot of a Windows Vista style progress barA progress bar shown in the Windows Vista widget style.
Screenshot of a Fusion style progress barA progress bar shown in the Fusion widget style.

参见 QProgressDialogGUI Design Handbook: Progress Indicator.

成员类型

enum QProgressBar::Direction

Specifies the reading direction of the text for vertical progress bars.

ConstantValueDescription
QProgressBar::TopToBottom0The text is rotated 90 degrees clockwise.
QProgressBar::BottomToTop1The text is rotated 90 degrees counter-clockwise.

Note that whether or not the text is drawn is dependent on the style. Currently CleanLooks and Plastique draw the text. Mac, Windows and WindowsXP style do not.

This enum was introduced or modified in Qt 4.1.

参见 textDirection.

属性

alignment : Qt::Alignment

This property holds the alignment of the progress bar

访问函数:

Qt::Alignment alignment() const
void setAlignment(Qt::Alignment alignment)

format : QString

This property holds the string used to generate the current text

%p - is replaced by the percentage completed. %v - is replaced by the current value. %m - is replaced by the total number of steps.

The default value is "%p%".

This property was introduced in Qt 4.2.

访问函数:

QString format() const
void setFormat(const QString &format)
void resetFormat()

参见 text().

invertedAppearance : bool

This property holds whether or not a progress bar shows its progress inverted

If this property is true, the progress bar grows in the other direction (e.g. from right to left). By default, the progress bar is not inverted.

This property was introduced in Qt 4.1.

访问函数:

bool invertedAppearance() const
void setInvertedAppearance(bool invert)

参见 orientation and layoutDirection.

maximum : int

This property holds the progress bar's maximum value

When setting this property, the minimum is adjusted if necessary to ensure that the range remains valid. If the current value falls outside the new range, the progress bar is reset with reset().

访问函数:

int maximum() const
void setMaximum(int maximum)

minimum : int

This property holds the progress bar's minimum value

When setting this property, the maximum is adjusted if necessary to ensure that the range remains valid. If the current value falls outside the new range, the progress bar is reset with reset().

访问函数:

int minimum() const
void setMinimum(int minimum)

orientation : Qt::Orientation

This property holds the orientation of the progress bar

The orientation must be Qt::Horizontal (the default) or Qt::Vertical.

This property was introduced in Qt 4.1.

访问函数:

Qt::Orientation orientation() const
void setOrientation(Qt::Orientation)

参见 invertedAppearance and textDirection.

text : const QString

This property holds the descriptive text shown with the progress bar

The text returned is the same as the text displayed in the center (or in some styles, to the left) of the progress bar.

The progress shown in the text may be smaller than the minimum value, indicating that the progress bar is in the "reset" state before any progress is set.

In the default implementation, the text either contains a percentage value that indicates the progress so far, or it is blank because the progress bar is in the reset state.

访问函数:

virtual QString text() const

textDirection : Direction

This property holds the reading direction of the text for vertical progress bars

This property has no impact on horizontal progress bars. By default, the reading direction is QProgressBar::TopToBottom.

This property was introduced in Qt 4.1.

访问函数:

QProgressBar::Direction textDirection() const
void setTextDirection(QProgressBar::Direction textDirection)

参见 orientation and textVisible.

textVisible : bool

This property holds whether the current completed percentage should be displayed

This property may be ignored by the style (e.g., QMacStyle never draws the text).

访问函数:

bool isTextVisible() const
void setTextVisible(bool visible)

参见 textDirection.

value : int

This property holds the progress bar's current value

Attempting to change the current value to one outside the minimum-maximum range has no effect on the current value.

访问函数:

int value() const
void setValue(int value)

Notifier signal:

void valueChanged(int value)

成员函数

QProgressBar::QProgressBar(QWidget *parent = Q_NULLPTR)

Constructs a progress bar with the given parent.

By default, the minimum step value is set to 0, and the maximum to 100.

参见 setRange().

QProgressBar::~QProgressBar()

Destructor.

[virtual protected] bool QProgressBar::event(QEvent *e)

重新实现 QObject::event().

[protected] void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const

Initialize option with the values from this QProgressBar. This method is useful for subclasses when they need a QStyleOptionProgressBar, but don't want to fill in all the information themselves.

参见 QStyleOption::initFrom().

[virtual] QSize QProgressBar::minimumSizeHint() const

重新实现 QWidget::minimumSizeHint().

[virtual protected] void QProgressBar::paintEvent(QPaintEvent *)

重新实现 QWidget::paintEvent().

[slot] void QProgressBar::reset()

Reset the progress bar. The progress bar "rewinds" and shows no progress.

[slot] void QProgressBar::setRange(int minimum, int maximum)

Sets the progress bar's minimum and maximum values to minimum and maximum respectively.

If maximum is smaller than minimum, minimum becomes the only legal value.

If the current value falls outside the new range, the progress bar is reset with reset().

The QProgressBar can be set to undetermined state by using setRange(0, 0).

参见 minimum and maximum.

[virtual] QSize QProgressBar::sizeHint() const

重新实现 QWidget::sizeHint().

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

This signal is emitted when the value shown in the progress bar changes. value is the new value shown by the progress bar.

Note: Notifier signal for property value.