The QDoubleSpinBox class provides a spin box widget that takes doubles. 更多...
| 頭: | #include <QDoubleSpinBox> |
| 繼承: | QAbstractSpinBox |
|
| QDoubleSpinBox (QWidget * parent = 0) | |
| QString | cleanText () const |
| int | decimals () const |
| double | maximum () const |
| double | minimum () const |
| QString | prefix () const |
| void | setDecimals (int prec ) |
| void | setMaximum (double max ) |
| void | setMinimum (double min ) |
| void | setPrefix (const QString & prefix ) |
| void | setRange (double minimum , double maximum ) |
| void | setSingleStep (double val ) |
| void | setSuffix (const QString & suffix ) |
| double | singleStep () const |
| QString | suffix () const |
| virtual QString | textFromValue (double value ) const |
| double | value () const |
| virtual double | valueFromText (const QString & text ) const |
| virtual void | fixup (QString & input ) const |
| virtual QValidator::State | validate (QString & text , int & pos ) const |
| void | setValue (double val ) |
| void | valueChanged (double d ) |
| void | valueChanged (const QString & text ) |
The QDoubleSpinBox class provides a spin box widget that takes doubles.
QDoubleSpinBox allows the user to choose a value by clicking the up and down buttons or by pressing Up or Down on the keyboard to increase or decrease the value currently displayed. The user can also type the value in manually. The spin box supports double values but can be extended to use different strings with validate (), textFromValue () 和 valueFromText ().
Every time the value changes QDoubleSpinBox 發射 valueChanged () signal. The current value can be fetched with value () 和設置采用 setValue ().
注意: QDoubleSpinBox will round numbers so they can be displayed with the current precision. In a QDoubleSpinBox with decimals set to 2, calling setValue (2.555) 將導緻 value () 返迴 2.56。
點擊嚮上和嚮下按鈕 (或使用鍵盤加速鍵的嚮上和嚮下箭頭) 將遞增 (或遞減) 當前值按步幅大小 singleStep ()。若想要改變此行為,可以重實現虛函數 stepBy ()。最小和最大值及步幅大小的設置可以使用某個構造函數,且稍後可以改變采用 setMinimum (), setMaximum () 和 setSingleStep ()。自鏇框默認擁有 2 位小數精度,但可以改變這使用 setDecimals ().
Most spin boxes are directional, but QDoubleSpinBox can also operate as a circular spin box, i.e. if the range is 0.0-99.9 and the current value is 99.9, clicking "up" will give 0 if wrapping () 被設為 true。使用 setWrapping () 若想要循環行為。
可以為顯示值前置和追加任意字符串指示,例如,貨幣 (或度量單位)。見 setPrefix () 和 setSuffix ()。自鏇框文本的檢索是采用 text () (包括任何 prefix () 和 suffix ()),或采用 cleanText () (沒有 prefix (),沒有 suffix () 且沒有前導或結尾空白)。
經常期望對用戶給齣特殊 (常常默認) 選擇,除數值範圍外。見 setSpecialValueText () for how to do this with QDoubleSpinBox .
另請參閱 QSpinBox , QDateTimeEdit , QSlider ,和 自鏇框範例 .
此特性保持自鏇框的文本,不包括任何前綴、後綴、或前導/結尾空白。
訪問函數:
| QString | cleanText () const |
另請參閱 text , QDoubleSpinBox::prefix ,和 QDoubleSpinBox::suffix .
This property holds the precision of the spin box, in decimals.
將用於顯示和解釋,自鏇框雙精度數的小數位數設為多少。
警告: 最大值對於 decimals 是 DBL_MAX_10_EXP + DBL_DIG (即 323),因為 double 類型的局限性。
注意:最大、最小及值可能改變,因更改此特性導緻。
訪問函數:
| int | decimals () const |
| void | setDecimals (int prec ) |
This property holds the maximum value of the spin box.
當設置此特性 minimum 有必要調節,以確保範圍仍然有效。
默認最大值為 99.99。
注意:會四捨五入最大值,以匹配 decimals 特性。
訪問函數:
| double | maximum () const |
| void | setMaximum (double max ) |
另請參閱 decimals and setRange ().
This property holds the minimum value of the spin box.
當設置此特性 maximum 有必要調節,以確保範圍仍然有效。
默認最小值為 0.0。
注意:會四捨五入最小值,以匹配 decimals 特性。
訪問函數:
| double | minimum () const |
| void | setMinimum (double min ) |
另請參閱 decimals , setRange (),和 specialValueText .
This property holds the spin box's prefix.
前綴會前置到顯示值開頭。典型用途是顯示度量單位 (或貨幣符號)。例如:
spinbox->setPrefix("$");
要關閉前綴顯示,把此特性設為空字符串。默認為無前綴。前綴不顯示,當 value () == minimum () 和 specialValueText () 有設置。
prefix() 返迴空字符串,若未設置前綴。
訪問函數:
| QString | prefix () const |
| void | setPrefix (const QString & prefix ) |
另請參閱 suffix (), setSuffix (), specialValueText (),和 setSpecialValueText ().
This property holds the step value.
當用戶使用箭頭改變自鏇框的值時,值將按 singleStep 數量遞增/遞減。默認值為 1.0。將 singleStep 值設為小於 0,什麼都不做。
訪問函數:
| double | singleStep () const |
| void | setSingleStep (double val ) |
This property holds the suffix of the spin box.
後綴會被追加到顯示值末尾。典型用法是顯示度量單位 (或貨幣符號)。例如:
spinbox->setSuffix(" km");
要關閉後綴顯示,將此特性設為空字符串。默認無後綴。後綴不顯示對於 minimum () 若 specialValueText () 有設置。
若未設置後綴,suffix() 返迴空字符串。
訪問函數:
| QString | suffix () const |
| void | setSuffix (const QString & suffix ) |
另請參閱 prefix (), setPrefix (), specialValueText (),和 setSpecialValueText ().
This property holds the value of the spin box.
setValue() will emit valueChanged() if the new value is different from the old one.
注意:值會被四捨五入,所以它可以與當前小數位數設置一起顯示。
訪問函數:
| double | value () const |
| void | setValue (double val ) |
通知程序信號:
| void | valueChanged (double d ) |
| void | valueChanged (const QString & text ) |
另請參閱 decimals .
構造自鏇框采用 0.0 作為最小值,99.99 作為最大值,步幅值 1.0,及 2 位小數位數精度。初始值被設為 0.00。自鏇框擁有給定 parent .
另請參閱 setMinimum (), setMaximum (),和 setSingleStep ().
[虛擬]
void
QDoubleSpinBox::
fixup
(
QString
&
input
) const
重實現自 QAbstractSpinBox::fixup ().
方便函數能設置 minimum and maximum 值采用單函數調用。
注意:會四捨五入最大和最小值,以匹配 decimals 特性。
setRange(minimum, maximum);
相當於:
setMinimum(minimum); setMaximum(maximum);
[虛擬]
QString
QDoubleSpinBox::
textFromValue
(
double
value
) const
此虛函數用於自鏇框,每當它需要顯示給定 value 。默認實現返迴的字符串包含 value 打印使用 QWidget::locale ().toString( value , QLatin1Char ('f'), decimals ()) and will remove the thousand separator. Reimplementations may return anything.
注意: QDoubleSpinBox 不會調用此函數對於 specialValueText () 且 prefix () 或 suffix () 應包括在返迴值中。
若重實現這,還可能需要重實現 valueFromText ().
另請參閱 valueFromText () 和 QLocale::groupSeparator ().
[虛擬]
QValidator::State
QDoubleSpinBox::
validate
(
QString
&
text
,
int
&
pos
) const
重實現自 QAbstractSpinBox::validate ().
[虛擬]
double
QDoubleSpinBox::
valueFromText
(const
QString
&
text
) const
此虛函數用於自鏇框,每當它需要解釋 text 由用戶作為值鍵入。
需要以非數字方式顯示自鏇框值的子類,需要重實現此函數。
注意: QDoubleSpinBox 處理 specialValueText () 單獨;此函數隻關心其它值。
另請參閱 textFromValue () 和 validate ().