QProgressBar 类
QProgressBar 类
QProgressBar 小部件提供水平 (或垂直) 进度条。
更多...
头:
#include
qmake:
QT += widgets
继承:
QWidget
所有成员列表,包括继承成员
公共类型
enum
Direction
{ TopToBottom, BottomToTop }
特性
alignment
: Qt::Alignment
format
: QString
invertedAppearance
: bool
maximum
: int
minimum
: int
orientation
: Qt::Orientation
text
: const QString
textDirection
: Direction
textVisible
: bool
value
: int
公共函数
QProgressBar
(QWidget *
parent
= nullptr)
virtual
~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 override
virtual QSize
sizeHint
() const override
公共槽
void
reset
()
void
setMaximum
(int
maximum
)
void
setMinimum
(int
minimum
)
void
setOrientation
(
Qt::Orientation
)
void
setRange
(int
minimum
, int
maximum
)
void
setValue
(int
value
)
信号
void
valueChanged
(int
value
)
保护函数
void
initStyleOption
(QStyleOptionProgressBar *
option
) const
重实现保护函数
virtual bool
event
(QEvent *
e
) override
virtual void
paintEvent
(
QPaintEvent *
) override
详细描述
进度条用于为用户给出操作进度指示,并安慰用户应用程序仍在运行。
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
()) 除以
maximum
() -
minimum
().
可以指定最小和最大步幅数采用
setMinimum
() 和
setMaximum
。设置当前步幅数采用
setValue
()。可以把进度条倒带到起始采用
reset
().
若把最小和最大两者设为 0,条展示繁忙指示器,而不是步进百分比。这很有用,例如,当使用 QNetworkAccessManager 下载项却无法确定要下载项的大小时。
另请参阅
QProgressDialog
and
GUI 设计手册:进度指示器
.
成员类型文档编制
enum QProgressBar::
Direction
指定阅读方向为
text
为垂直进度条。
常量
值
描述
QProgressBar::TopToBottom
0
文本被顺时针旋转 90 度。
QProgressBar::BottomToTop
1
文本被逆时针旋转 90 度。
注意:是否绘制文本取决于风格。目前 CleanLooks 和 Plastique 风格绘制文本。Mac、Windows 及 WindowsVista 风格不绘制文本。
该枚举在 Qt 4.1 引入或被修改。
另请参阅
textDirection
.
特性文档编制
alignment
:
Qt::Alignment
此特性保持进度条的对齐
访问函数:
Qt::Alignment
alignment
() const
void
setAlignment
(Qt::Alignment
alignment
)
format
:
QString
此特性保持用于生成当前文本的字符串
%p - 由完成百分比替换。%v - 由当前值替换。%m - 由总步数替换。
默认值为 "%p%"。
该特性在 Qt 4.2 引入。
访问函数:
QString
format
() const
void
setFormat
(const QString &
format
)
void
resetFormat
()
另请参阅
text
().
invertedAppearance
:
bool
此特性保持进度条是否展示其进度的反转
若此特性为
true
,进度条朝另一方向 (如:从右到左) 增长。默认情况下,进度条不反转。
该特性在 Qt 4.1 引入。
访问函数:
bool
invertedAppearance
() const
void
setInvertedAppearance
(bool
invert
)
另请参阅
orientation
and
layoutDirection
.
maximum
:
int
此特性保持进度条的最大值
当设置此特性时,
minimum
被调节,若有必要,确保范围仍然有效。若当前值落在新范围外,重置进度条采用
reset
().
访问函数:
int
maximum
() const
void
setMaximum
(int
maximum
)
minimum
:
int
此特性保持进度条的最小值
当设置此特性时,
maximum
被调节,若有必要,确保范围仍然有效。若当前值落在新范围外,重置进度条采用
reset
().
访问函数:
int
minimum
() const
void
setMinimum
(int
minimum
)
orientation
:
Qt::Orientation
此特性保持进度条的方向
取向必须是
Qt::Horizontal
(默认) 或
Qt::Vertical
.
该特性在 Qt 4.1 引入。
访问函数:
Qt::Orientation
orientation
() const
void
setOrientation
(
Qt::Orientation
)
另请参阅
invertedAppearance
and
textDirection
.
text
: const
QString
此特性保持采用进度条展示的描述性文本
返回文本同进度条居中 (或某些风格左侧) 显示文本。
文本中显示进度可能小于最小值,指示进度条处于重置状态,在任何进度被设置之前。
在默认实现中,文本包含指示到目前为止的进度百分比值,或为空 (因为进度条处于重置状态)。
访问函数:
virtual QString
text
() const
textDirection
:
Direction
此特性保持阅读方向为
text
为垂直进度条
此特性对水平进度条没有影响。默认情况下,读取方向为
QProgressBar::TopToBottom
.
该特性在 Qt 4.1 引入。
访问函数:
QProgressBar::Direction
textDirection
() const
void
setTextDirection
(QProgressBar::Direction
textDirection
)
另请参阅
orientation
and
textVisible
.
textVisible
:
bool
此特性保持是否应显示当前已完成的百分比
此特性可能被样式忽略 (如:QMacStyle 从不绘制文本)。
访问函数:
bool
isTextVisible
() const
void
setTextVisible
(bool
visible
)
另请参阅
textDirection
.
value
:
int
此特性保持进度条的当前值
试图把当前值更改为最小-最大范围之外的某一值,不影响当前值。
访问函数:
int
value
() const
void
setValue
(int
value
)
通知程序信号:
void
valueChanged
(int
value
)
成员函数文档编制
QProgressBar::
QProgressBar
(
QWidget
*
parent
= nullptr)
构造进度条采用给定
parent
.
默认情况下,最小步幅值被设为 0,而最大为 100。
另请参阅
setRange
().
[slot]
void
QProgressBar::
reset
()
重置进度条。进度条倒带且不展示进度。
[slot]
void
QProgressBar::
setRange
(
int
minimum
,
int
maximum
)
把进度条的最小和最大值设为
minimum
and
maximum
分别。
若
maximum
<
minimum
,
minimum
变为唯一合法值。
若当前值落在新范围之外,进度条被重置采用
reset
().
The
QProgressBar
可以被设为不确定状态通过使用 setRange(0, 0)。
另请参阅
minimum
and
maximum
.
[signal]
void
QProgressBar::
valueChanged
(
int
value
)
此信号被发射当进度条展示值改变时。
value
是由进度条展示的新值。
注意:
通知程序信号对于特性
value
.
[虚拟]
QProgressBar::
~QProgressBar
()
析构函数。
[override virtual protected]
bool
QProgressBar::
event
(
QEvent
*
e
)
重实现:
QWidget::event
(QEvent *event).
[protected]
void
QProgressBar::
initStyleOption
(
QStyleOptionProgressBar
*
option
) const
初始化
option
采用值来自此
QProgressBar
。此方法对子类是有用的,当需要
QStyleOptionProgressBar
,但不希望自己填充所有信息。
另请参阅
QStyleOption::initFrom
().
[override virtual]
QSize
QProgressBar::
minimumSizeHint
() const
重实现访问函数为特性:
QWidget::minimumSizeHint
.
[override virtual protected]
void
QProgressBar::
paintEvent
(
QPaintEvent *
)
重实现:
QWidget::paintEvent
(QPaintEvent *event).
[override virtual]
QSize
QProgressBar::
sizeHint
() const
重实现访问函数为特性:
QWidget::sizeHint
.