QProgressBar 類

The 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 )

信號

void valueChanged (int value )

保護函數

void initStyleOption (QStyleOptionProgressBar * option ) const

重實現保護函數

virtual bool event (QEvent * e )
virtual void paintEvent ( QPaintEvent * )

額外繼承成員

詳細描述

The QProgressBar 小部件提供水平 (或垂直) 進度條。

進度條用於為用戶給齣操作進度指示,並安慰用戶應用程序仍在運行。

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 和 WindowsXP 樣式不繪製。

該枚舉在 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 = Q_NULLPTR)

構造進度條采用給定 parent .

默認情況下,最小步幅值被設為 0,而最大為 100。

另請參閱 setRange ().

QProgressBar:: ~QProgressBar ()

析構函數。

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

重實現自 QObject::event ().

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

初始化 option 采用值來自此 QProgressBar 。此方法對子類是有用的,當需要 QStyleOptionProgressBar ,但不希望自己填充所有信息。

另請參閱 QStyleOption::initFrom ().

[虛擬] QSize QProgressBar:: minimumSizeHint () const

重實現自 QWidget::minimumSizeHint ().

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

重實現自 QWidget::paintEvent ().

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

[虛擬] QSize QProgressBar:: sizeHint () const

重實現自 QWidget::sizeHint ().

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

此信號被發射當進度條展示值改變時。 value 是由進度條展示的新值。

注意: 通知程序信號對於特性 value .