QAbstractSpinBox 类

QAbstractSpinBox class provides a spinbox and a line edit to display values. 更多...

头: #include <QAbstractSpinBox>
qmake: QT += widgets
继承: QWidget
继承者:

QDateTimeEdit , QDoubleSpinBox ,和 QSpinBox

公共类型

enum ButtonSymbols { UpDownArrows, PlusMinus, NoButtons }
enum CorrectionMode { CorrectToPreviousValue, CorrectToNearestValue }
flags StepEnabled
enum StepEnabledFlag { StepNone, StepUpEnabled, StepDownEnabled }

特性

公共函数

QAbstractSpinBox (QWidget * parent = Q_NULLPTR)
~QAbstractSpinBox ()
Qt::Alignment alignment () const
ButtonSymbols buttonSymbols () const
CorrectionMode correctionMode () const
virtual void fixup (QString & input ) const
bool hasAcceptableInput () const
bool hasFrame () const
void interpretText ()
bool isAccelerated () const
bool isGroupSeparatorShown () const
bool isReadOnly () const
bool keyboardTracking () const
void setAccelerated (bool on )
void setAlignment (Qt::Alignment flag )
void setButtonSymbols (ButtonSymbols bs )
void setCorrectionMode (CorrectionMode cm )
void setFrame ( bool )
void setGroupSeparatorShown (bool shown )
void setKeyboardTracking (bool kt )
void setReadOnly (bool r )
void setSpecialValueText (const QString & txt )
void setWrapping (bool w )
QString specialValueText () const
virtual void stepBy (int steps )
QString text () const
virtual QValidator::State validate (QString & input , int & pos ) const
bool wrapping () const

重实现公共函数

virtual bool event (QEvent * event ) override
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query ) const override
virtual QSize minimumSizeHint () const override
virtual QSize sizeHint () const override

公共槽

virtual void clear ()
void selectAll ()
void stepDown ()
void stepUp ()

信号

void editingFinished ()

保护函数

void initStyleOption (QStyleOptionSpinBox * option ) const
QLineEdit * lineEdit () const
void setLineEdit (QLineEdit * lineEdit )
virtual StepEnabled stepEnabled () const

重实现保护函数

virtual void changeEvent (QEvent * event ) override
virtual void closeEvent (QCloseEvent * event ) override
virtual void contextMenuEvent (QContextMenuEvent * event ) override
virtual void focusInEvent (QFocusEvent * event ) override
virtual void focusOutEvent (QFocusEvent * event ) override
virtual void hideEvent (QHideEvent * event ) override
virtual void keyPressEvent (QKeyEvent * event ) override
virtual void keyReleaseEvent (QKeyEvent * event ) override
virtual void mouseMoveEvent (QMouseEvent * event ) override
virtual void mousePressEvent (QMouseEvent * event ) override
virtual void mouseReleaseEvent (QMouseEvent * event ) override
virtual void paintEvent (QPaintEvent * event ) override
virtual void resizeEvent (QResizeEvent * event ) override
virtual void showEvent (QShowEvent * event ) override
virtual void timerEvent (QTimerEvent * event ) override
virtual void wheelEvent (QWheelEvent * event ) override

额外继承成员

详细描述

QAbstractSpinBox class provides a spinbox and a line edit to display values.

此类被设计作为 Widget 的通用超类像 QSpinBox , QDoubleSpinBox and QDateTimeEdit

这里是类的主要特性:

  1. text : The text that is displayed in the QAbstractSpinBox .
  2. alignment : The alignment of the text in the QAbstractSpinBox .
  3. wrapping : Whether the QAbstractSpinBox wraps from the minimum value to the maximum value and vica versa.

QAbstractSpinBox provides a virtual stepBy () 函数每当用户触发步进时调用。此函数接受整数值表示已执行多少步。如:按下 Qt::Key_Down 将触发调用 stepBy (-1).

QAbstractSpinBox also provide a virtual function stepEnabled () 以确定在任何时候是否允许加/减步进。此函数返回位集的 StepEnabled .

另请参阅 QAbstractSlider , QSpinBox , QDoubleSpinBox , QDateTimeEdit ,和 自旋框范例 .

成员类型文档编制

enum QAbstractSpinBox:: ButtonSymbols

此枚举类型描述可以在自旋框按钮中显示的符号。

常量 描述
QAbstractSpinBox::UpDownArrows 0 经典风格小箭头。
QAbstractSpinBox::PlusMinus 1 + and - 符号。
QAbstractSpinBox::NoButtons 2 不显示按钮。

另请参阅 QAbstractSpinBox::buttonSymbols .

enum QAbstractSpinBox:: CorrectionMode

此枚举类型描述的自旋框模式用于校正 中间体 值若编辑完成。

常量 描述
QAbstractSpinBox::CorrectToPreviousValue 0 The spinbox will revert to the last valid value.
QAbstractSpinBox::CorrectToNearestValue 1 The spinbox will revert to the nearest valid value.

另请参阅 correctionMode .

enum QAbstractSpinBox:: StepEnabledFlag
flags QAbstractSpinBox:: StepEnabled

常量
QAbstractSpinBox::StepNone 0x00
QAbstractSpinBox::StepUpEnabled 0x01
QAbstractSpinBox::StepDownEnabled 0x02

The StepEnabled type is a typedef for QFlags <StepEnabledFlag>. It stores an OR combination of StepEnabledFlag values.

特性文档编制

accelerated : bool

此特性保持自旋框是否会加快步进的频率,当按下向上/向下步进按钮时。

若启用,自旋框会更快地递增/递减值,当按下按钮时间越长时。

该特性在 Qt 4.2 引入。

访问函数:

bool isAccelerated () const
void setAccelerated (bool on )

acceptableInput : const bool

此特性保持输入是否满足当前验证

该特性在 Qt 4.2 引入。

访问函数:

bool hasAcceptableInput () const

另请参阅 validate (), fixup (),和 correctionMode .

alignment : Qt::Alignment

此特性保持自旋框的对齐方式

可能的值是 Qt::AlignLeft , Qt::AlignRight ,和 Qt::AlignHCenter .

默认情况下,对齐方式为 Qt::AlignLeft

试图把对齐方式设为非法标志的组合,会什么都不做。

访问函数:

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

另请参阅 Qt::Alignment .

buttonSymbols : ButtonSymbols

此特性保持当前按钮的符号模式

可能值可以是 UpDownArrows or PlusMinus 。默认为 UpDownArrows .

注意:某些风格可能渲染 PlusMinus and UpDownArrows 同等。

访问函数:

ButtonSymbols buttonSymbols () const
void setButtonSymbols (ButtonSymbols bs )

另请参阅 ButtonSymbols .

correctionMode : CorrectionMode

此特性保持的模式用于校正 中间体 值若编辑完成

默认模式为 QAbstractSpinBox::CorrectToPreviousValue .

该特性在 Qt 4.2 引入。

访问函数:

CorrectionMode correctionMode () const
void setCorrectionMode (CorrectionMode cm )

另请参阅 acceptableInput , validate (),和 fixup ().

frame : bool

此特性保持自旋框是否采用框架绘制自身

If enabled (the default) the spin box draws itself inside a frame, otherwise the spin box draws itself without any frame.

访问函数:

bool hasFrame () const
void setFrame ( bool )

keyboardTracking : bool

此特性保持是否为自旋框启用键盘跟踪。

If keyboard tracking is enabled (the default), the spinbox emits the valueChanged() signal while the new value is being entered from the keyboard.

E.g. when the user enters the value 600 by typing 6, 0, and 0, the spinbox emits 3 signals with the values 6, 60, and 600 respectively.

If keyboard tracking is disabled, the spinbox doesn't emit the valueChanged() signal while typing. It emits the signal later, when the return key is pressed, when keyboard focus is lost, or when other spinbox functionality is used, e.g. pressing an arrow key.

该特性在 Qt 4.3 引入。

访问函数:

bool keyboardTracking () const
void setKeyboardTracking (bool kt )

readOnly : bool

此特性保持自旋框是否为只读。

在只读模式下,用户仍可以将文本拷贝到剪贴板,或拖放文本;但无法编辑它。

QLineEdit QAbstractSpinBox 在只读模式下不展示光标。

访问函数:

bool isReadOnly () const
void setReadOnly (bool r )

另请参阅 QLineEdit::readOnly .

showGroupSeparator : bool

此特性保持是否启用千位分隔符。默认情况下,此特性为 false。

该特性在 Qt 5.3 引入。

访问函数:

bool isGroupSeparatorShown () const
void setGroupSeparatorShown (bool shown )

specialValueText : QString

此特性保持特殊值文本

若设置,自旋框会显示此文本而非数字值,在当前值等于 minimum() 时。典型用途是指示此抉择具有特殊 (默认) 含义。

例如,若自旋框允许用户选取比例因子 (或缩放级别) 为显示图像,且应用程序能够自动选取允许把图像完整拟合在显示窗口中的某一值,就可以像这样设置自旋框:

    QSpinBox *zoomSpinBox = new QSpinBox;
    zoomSpinBox->setRange(0, 1000);
    zoomSpinBox->setSingleStep(10);
    zoomSpinBox->setSuffix("%");
    zoomSpinBox->setSpecialValueText(tr("Automatic"));
    zoomSpinBox->setValue(100);
					

接着,用户将能在 1% 到 1000% 之间选取比例,或选择 Auto 以将其留给应用程序去选取。然后,代码必须把自旋框 0 值解释为来自用户的请求,以缩放图像为拟合在窗口内。

所有被显示值带前缀和后缀 (若有设置), except 为特殊值,仅展示特殊值文本。此特殊文本被传入 QSpinBox::valueChanged () 信号传递 QString .

要关闭特殊值文本显示,调用此函数采用空字符串。默认为无特殊值文本 (即:照常展示数字值)。

specialValueText() 返回空字符串,若未设置特殊值文本。

访问函数:

QString specialValueText () const
void setSpecialValueText (const QString & txt )

text : const QString

此特性保持自旋框的文本,包括任何前缀和后缀

没有默认文本。

访问函数:

QString text () const

wrapping : bool

此特性保持自旋框是否循环。

If wrapping is true stepping up from maximum() value will take you to the minimum() value and vica versa. Wrapping only make sense if you have minimum() and maximum() values set.

QSpinBox *spinBox = new QSpinBox(this);
spinBox->setRange(0, 100);
spinBox->setWrapping(true);
spinBox->setValue(100);
spinBox->stepBy(1);
// value is 0
					

访问函数:

bool wrapping () const
void setWrapping (bool w )

另请参阅 QSpinBox::minimum () 和 QSpinBox::maximum ().

成员函数文档编制

QAbstractSpinBox:: QAbstractSpinBox ( QWidget * parent = Q_NULLPTR)

构造抽象 Spinbox 采用给定 parent 采用默认 wrapping ,和 alignment 特性。

QAbstractSpinBox:: ~QAbstractSpinBox ()

被调用当 QAbstractSpinBox 被销毁。

[override virtual protected] void QAbstractSpinBox:: changeEvent ( QEvent * event )

重实现自 QWidget::changeEvent ().

[virtual slot] void QAbstractSpinBox:: clear ()

清零所有文本的 lineedit,除前缀和后缀外。

[override virtual protected] void QAbstractSpinBox:: closeEvent ( QCloseEvent * event )

重实现自 QWidget::closeEvent ().

[override virtual protected] void QAbstractSpinBox:: contextMenuEvent ( QContextMenuEvent * event )

重实现自 QWidget::contextMenuEvent ().

[signal] void QAbstractSpinBox:: editingFinished ()

This signal is emitted editing is finished. This happens when the spinbox loses focus and when enter is pressed.

[override virtual] bool QAbstractSpinBox:: event ( QEvent * event )

重实现自 QObject::event ().

[virtual] void QAbstractSpinBox:: fixup ( QString & input ) const

This virtual function is called by the QAbstractSpinBox input is not validated to QValidator::Acceptable when Return is pressed or interpretText () is called. It will try to change the text so it is valid. Reimplemented in the various subclasses.

[override virtual protected] void QAbstractSpinBox:: focusInEvent ( QFocusEvent * event )

重实现自 QWidget::focusInEvent ().

[override virtual protected] void QAbstractSpinBox:: focusOutEvent ( QFocusEvent * event )

重实现自 QWidget::focusOutEvent ().

[override virtual protected] void QAbstractSpinBox:: hideEvent ( QHideEvent * event )

重实现自 QWidget::hideEvent ().

[protected] void QAbstractSpinBox:: initStyleOption ( QStyleOptionSpinBox * option ) const

初始化 option 采用值来自此 QSpinBox 。此方法对子类是有用的,当需要 QStyleOptionSpinBox ,但不希望自己填充所有信息。

另请参阅 QStyleOption::initFrom ().

[override virtual] QVariant QAbstractSpinBox:: inputMethodQuery ( Qt::InputMethodQuery query ) const

重实现自 QWidget::inputMethodQuery ().

void QAbstractSpinBox:: interpretText ()

This function interprets the text of the spin box. If the value has changed since last interpretation it will emit signals.

[override virtual protected] void QAbstractSpinBox:: keyPressEvent ( QKeyEvent * event )

重实现自 QWidget::keyPressEvent ().

This function handles keyboard input.

The following keys are handled specifically:

Enter/Return This will reinterpret the text and emit a signal even if the value has not changed since last time a signal was emitted.
Up This will invoke stepBy (1)
Down This will invoke stepBy (-1)
Page up This will invoke stepBy (10)
Page down This will invoke stepBy (-10)

[override virtual protected] void QAbstractSpinBox:: keyReleaseEvent ( QKeyEvent * event )

重实现自 QWidget::keyReleaseEvent ().

[protected] QLineEdit *QAbstractSpinBox:: lineEdit () const

This function returns a pointer to the line edit of the spin box.

另请参阅 setLineEdit ().

[override virtual] QSize QAbstractSpinBox:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

[override virtual protected] void QAbstractSpinBox:: mouseMoveEvent ( QMouseEvent * event )

重实现自 QWidget::mouseMoveEvent ().

[override virtual protected] void QAbstractSpinBox:: mousePressEvent ( QMouseEvent * event )

重实现自 QWidget::mousePressEvent ().

[override virtual protected] void QAbstractSpinBox:: mouseReleaseEvent ( QMouseEvent * event )

重实现自 QWidget::mouseReleaseEvent ().

[override virtual protected] void QAbstractSpinBox:: paintEvent ( QPaintEvent * event )

重实现自 QWidget::paintEvent ().

[override virtual protected] void QAbstractSpinBox:: resizeEvent ( QResizeEvent * event )

重实现自 QWidget::resizeEvent ().

[slot] void QAbstractSpinBox:: selectAll ()

Selects all the text in the spinbox except the prefix and suffix.

[protected] void QAbstractSpinBox:: setLineEdit ( QLineEdit * lineEdit )

Sets the line edit of the spinbox to be lineEdit instead of the current line edit widget. lineEdit can not be 0.

QAbstractSpinBox takes ownership of the new lineEdit

QLineEdit::validator () 为 lineEdit returns 0, the internal validator of the spinbox will be set on the line edit.

另请参阅 lineEdit ().

[override virtual protected] void QAbstractSpinBox:: showEvent ( QShowEvent * event )

重实现自 QWidget::showEvent ().

[override virtual] QSize QAbstractSpinBox:: sizeHint () const

重实现自 QWidget::sizeHint ().

[virtual] void QAbstractSpinBox:: stepBy ( int steps )

Virtual function that is called whenever the user triggers a step. The steps parameter indicates how many steps were taken, e.g. Pressing Qt::Key_Down will trigger a call to stepBy(-1), whereas pressing Qt::Key_Prior will trigger a call to stepBy(10).

If you subclass QAbstractSpinBox you must reimplement this function. Note that this function is called even if the resulting value will be outside the bounds of minimum and maximum. It's this function's job to handle these situations.

[slot] void QAbstractSpinBox:: stepDown ()

Steps down by one linestep Calling this slot is analogous to calling stepBy (-1);

另请参阅 stepBy () 和 stepUp ().

[virtual protected] StepEnabled QAbstractSpinBox:: stepEnabled () const

Virtual function that determines whether stepping up and down is legal at any given time.

The up arrow will be painted as disabled unless (stepEnabled() & StepUpEnabled ) != 0.

The default implementation will return ( StepUpEnabled | StepDownEnabled ) if wrapping is turned on. Else it will return StepDownEnabled if value is > minimum() or'ed with StepUpEnabled if value < maximum().

If you subclass QAbstractSpinBox you will need to reimplement this function.

另请参阅 QSpinBox::minimum (), QSpinBox::maximum (),和 wrapping ().

[slot] void QAbstractSpinBox:: stepUp ()

Steps up by one linestep Calling this slot is analogous to calling stepBy (1);

另请参阅 stepBy () 和 stepDown ().

[override virtual protected] void QAbstractSpinBox:: timerEvent ( QTimerEvent * event )

重实现自 QObject::timerEvent ().

[virtual] QValidator::State QAbstractSpinBox:: validate ( QString & input , int & pos ) const

This virtual function is called by the QAbstractSpinBox to determine whether input is valid. The pos parameter indicates the position in the string. Reimplemented in the various subclasses.

[override virtual protected] void QAbstractSpinBox:: wheelEvent ( QWheelEvent * event )

重实现自 QWidget::wheelEvent ().