QAbstractSpinBox 类提供自旋框和行编辑,以显示值。 更多...
头: | #include <QAbstractSpinBox> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QWidget |
继承者: | QDateTimeEdit , QDoubleSpinBox ,和 QSpinBox |
enum | ButtonSymbols { UpDownArrows, PlusMinus, NoButtons } |
enum | CorrectionMode { CorrectToPreviousValue, CorrectToNearestValue } |
flags | StepEnabled |
enum | StepEnabledFlag { StepNone, StepUpEnabled, StepDownEnabled } |
enum | StepType { DefaultStepType, AdaptiveDecimalStepType } |
|
|
QAbstractSpinBox (QWidget * parent = nullptr) | |
virtual | ~QAbstractSpinBox () |
Qt::Alignment | alignment () const |
QAbstractSpinBox::ButtonSymbols | buttonSymbols () const |
QAbstractSpinBox::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 (QAbstractSpinBox::ButtonSymbols bs ) |
void | setCorrectionMode (QAbstractSpinBox::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 () |
virtual void | initStyleOption (QStyleOptionSpinBox * option ) const |
QLineEdit * | lineEdit () const |
void | setLineEdit (QLineEdit * lineEdit ) |
virtual QAbstractSpinBox::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 |
此类被设计作为 Widget 的通用超类像 QSpinBox , QDoubleSpinBox and QDateTimeEdit
这里是类的主要特性:
QAbstractSpinBox 提供虚拟 stepBy () 函数每当用户触发步进时调用。此函数接受整数值表示已执行多少步。如:按下 Qt::Key_Down 将触发调用 stepBy (-1).
当用户触发步进时的同时按住 Qt::ControlModifier ,QAbstractSpinBox 步进 10 而不是单步。此步进修饰符影响滚轮事件、键事件及自旋框按钮交互。注意:在 macOS,Ctrl 键相当于 Command 键。
从 Qt 5.12 起, QStyle::SH_SpinBox_StepModifier 可以用来选择 Qt::KeyboardModifier 递增步幅速率。 Qt::NoModifier 禁用此特征。
QAbstractSpinBox 还提供虚函数 stepEnabled () 以确定在任何时候是否允许加/减步进。此函数返回位集的 StepEnabled .
另请参阅 QAbstractSlider , QSpinBox , QDoubleSpinBox , QDateTimeEdit ,和 自旋框范例 .
此枚举类型描述可以在自旋框按钮中显示的符号。
常量 | 值 | 描述 |
---|---|---|
QAbstractSpinBox::UpDownArrows
|
0
|
经典风格小箭头。 |
QAbstractSpinBox::PlusMinus
|
1
|
+ and - 符号。 |
QAbstractSpinBox::NoButtons
|
2
|
不显示按钮。 |
另请参阅 QAbstractSpinBox::buttonSymbols .
此枚举类型描述的自旋框模式用于校正 中间体 值若编辑完成。
常量 | 值 | 描述 |
---|---|---|
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 .
常量 | 值 |
---|---|
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.
常量 | 值 |
---|---|
QAbstractSpinBox::DefaultStepType
|
0
|
QAbstractSpinBox::AdaptiveDecimalStepType
|
1
|
此特性保持自旋框是否会加快步进的频率,当按下向上/向下步进按钮时。
若启用,自旋框会更快地递增/递减值,当按下按钮时间越长时。
访问函数:
bool | isAccelerated () const |
void | setAccelerated (bool on ) |
[read-only]
acceptableInput
: const
bool
此特性保持输入是否满足当前验证
访问函数:
bool | hasAcceptableInput () const |
另请参阅 validate (), fixup (),和 correctionMode .
此特性保持自旋框的对齐方式
可能的值是 Qt::AlignLeft , Qt::AlignRight ,和 Qt::AlignHCenter .
默认情况下,对齐方式为 Qt::AlignLeft
试图把对齐方式设为非法标志的组合,会什么都不做。
访问函数:
Qt::Alignment | alignment () const |
void | setAlignment (Qt::Alignment flag ) |
另请参阅 Qt::Alignment .
此特性保持当前按钮的符号模式
可能值可以是
UpDownArrows
or
PlusMinus
。默认为
UpDownArrows
.
注意:某些风格可能渲染 PlusMinus and UpDownArrows 同等。
访问函数:
QAbstractSpinBox::ButtonSymbols | buttonSymbols () const |
void | setButtonSymbols (QAbstractSpinBox::ButtonSymbols bs ) |
另请参阅 ButtonSymbols .
此特性保持的模式用于校正 中间体 值若编辑完成
默认模式为 QAbstractSpinBox::CorrectToPreviousValue .
访问函数:
QAbstractSpinBox::CorrectionMode | correctionMode () const |
void | setCorrectionMode (QAbstractSpinBox::CorrectionMode cm ) |
另请参阅 acceptableInput , validate (),和 fixup ().
此特性保持自旋框是否采用框架绘制自身
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) |
此特性保持是否为自旋框启用键盘跟踪。
If keyboard tracking is enabled (the default), the spinbox emits the valueChanged() and textChanged() signals 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() and textChanged() signals while typing. It emits the signals 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.
访问函数:
bool | keyboardTracking () const |
void | setKeyboardTracking (bool kt ) |
此特性保持自旋框是否为只读。
在只读模式下,用户仍可以将文本拷贝到剪贴板,或拖放文本;但无法编辑它。
The QLineEdit 在 QAbstractSpinBox 在只读模式下不展示光标。
访问函数:
bool | isReadOnly () const |
void | setReadOnly (bool r ) |
另请参阅 QLineEdit::readOnly .
此特性保持是否启用千位分隔符。默认情况下,此特性为 false。
访问函数:
bool | isGroupSeparatorShown () const |
void | setGroupSeparatorShown (bool shown ) |
此特性保持特殊值文本
若设置,自旋框会显示此文本而非数字值,在当前值等于 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::textChanged () 信号传递 QString .
要关闭特殊值文本显示,调用此函数采用空字符串。默认为无特殊值文本 (即:照常展示数字值)。
specialValueText() 返回空字符串,若未设置特殊值文本。
访问函数:
QString | specialValueText () const |
void | setSpecialValueText (const QString & txt ) |
[read-only]
text
: const
QString
此特性保持自旋框的文本,包括任何前缀和后缀
没有默认文本。
访问函数:
QString | text () const |
此特性保持自旋框是否循环。
若环绕为 true,从 maximum() 值向上步进会到 minimum() 值,反之亦然。环绕才有意义,若有设置 maximum() 和 minimum() 值。
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 ().
[explicit]
QAbstractSpinBox::
QAbstractSpinBox
(
QWidget
*
parent
= nullptr)
构造抽象 Spinbox 采用给定 parent 采用默认 wrapping ,和 alignment 特性。
[virtual]
QAbstractSpinBox::
~QAbstractSpinBox
()
被调用当 QAbstractSpinBox 被销毁。
[override virtual protected]
void
QAbstractSpinBox::
changeEvent
(
QEvent
*
event
)
重实现: QWidget::changeEvent (QEvent *event).
[virtual slot]
void
QAbstractSpinBox::
clear
()
清零所有文本的 lineedit,除前缀和后缀外。
[override virtual protected]
void
QAbstractSpinBox::
closeEvent
(
QCloseEvent
*
event
)
重实现: QWidget::closeEvent (QCloseEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
contextMenuEvent
(
QContextMenuEvent
*
event
)
重实现: QWidget::contextMenuEvent (QContextMenuEvent *event).
[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
)
重实现: QWidget::event (QEvent *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 (QFocusEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
focusOutEvent
(
QFocusEvent
*
event
)
重实现: QWidget::focusOutEvent (QFocusEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
hideEvent
(
QHideEvent
*
event
)
重实现: QWidget::hideEvent (QHideEvent *event).
[virtual protected]
void
QAbstractSpinBox::
initStyleOption
(
QStyleOptionSpinBox
*
option
) const
初始化 option 采用值来自此 QSpinBox 。此方法对子类是有用的,当需要 QStyleOptionSpinBox ,但不希望自己填充所有信息。
另请参阅 QStyleOption::initFrom ().
[override virtual]
QVariant
QAbstractSpinBox::
inputMethodQuery
(
Qt::InputMethodQuery
query
) const
重实现: QWidget::inputMethodQuery(Qt::InputMethodQuery query) const .
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 (QKeyEvent *event).
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) |
另请参阅 stepBy ().
[override virtual protected]
void
QAbstractSpinBox::
keyReleaseEvent
(
QKeyEvent
*
event
)
重实现: QWidget::keyReleaseEvent (QKeyEvent *event).
[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 (QMouseEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
mousePressEvent
(
QMouseEvent
*
event
)
重实现: QWidget::mousePressEvent (QMouseEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
mouseReleaseEvent
(
QMouseEvent
*
event
)
重实现: QWidget::mouseReleaseEvent (QMouseEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
paintEvent
(
QPaintEvent
*
event
)
重实现: QWidget::paintEvent (QPaintEvent *event).
[override virtual protected]
void
QAbstractSpinBox::
resizeEvent
(
QResizeEvent
*
event
)
重实现: QWidget::resizeEvent (QResizeEvent *event).
[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
不可以是
nullptr
.
QAbstractSpinBox takes ownership of the new lineEdit
若
QLineEdit::validator
() 为
lineEdit
返回
nullptr
, the internal validator of the spinbox will be set on the line edit.
另请参阅 lineEdit ().
[override virtual protected]
void
QAbstractSpinBox::
showEvent
(
QShowEvent
*
event
)
重实现: QWidget::showEvent (QShowEvent *event).
[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. For example, pressing
Qt::Key_Down
将触发调用
stepBy(-1)
, whereas pressing
Qt::Key_PageUp
将触发调用
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.
另请参阅 stepUp (), stepDown (),和 keyPressEvent ().
[slot]
void
QAbstractSpinBox::
stepDown
()
Steps down by one linestep Calling this slot is analogous to calling stepBy (-1);
[virtual protected]
QAbstractSpinBox::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);
[override virtual protected]
void
QAbstractSpinBox::
timerEvent
(
QTimerEvent
*
event
)
重实现: QObject::timerEvent (QTimerEvent *event).
[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 (QWheelEvent *event).