
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQAbstractSpinBox class provides a spinbox and a line edit to display values.More...
| Header: | #include <QAbstractSpinBox> |
| Inherits: | QWidget |
| Inherited By: |
| enum | ButtonSymbols { UpDownArrows, PlusMinus, NoButtons } |
| enum | CorrectionMode { CorrectToPreviousValue, CorrectToNearestValue } |
| flags | StepEnabled |
| enum | StepEnabledFlag { StepNone, StepUpEnabled, StepDownEnabled } |
|
|
| QAbstractSpinBox(QWidget * parent = 0) | |
| ~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 | 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 | 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) |
| virtual QVariant | inputMethodQuery(Qt::InputMethodQuery query) const |
| virtual QSize | minimumSizeHint() const |
| virtual QSize | sizeHint() const |
| void | editingFinished() |
| void | initStyleOption(QStyleOptionSpinBox * option) const |
| QLineEdit * | lineEdit() const |
| void | setLineEdit(QLineEdit * lineEdit) |
| virtual StepEnabled | stepEnabled() const |
| virtual void | changeEvent(QEvent * event) |
| virtual void | closeEvent(QCloseEvent * event) |
| virtual void | contextMenuEvent(QContextMenuEvent * event) |
| virtual void | focusInEvent(QFocusEvent * event) |
| virtual void | focusOutEvent(QFocusEvent * event) |
| virtual void | hideEvent(QHideEvent * event) |
| virtual void | keyPressEvent(QKeyEvent * event) |
| virtual void | keyReleaseEvent(QKeyEvent * event) |
| virtual void | mouseMoveEvent(QMouseEvent * event) |
| virtual void | mousePressEvent(QMouseEvent * event) |
| virtual void | mouseReleaseEvent(QMouseEvent * event) |
| virtual void | paintEvent(QPaintEvent * event) |
| virtual void | resizeEvent(QResizeEvent * event) |
| virtual void | showEvent(QShowEvent * event) |
| virtual void | timerEvent(QTimerEvent * event) |
| virtual void | wheelEvent(QWheelEvent * event) |
TheQAbstractSpinBox class provides a spinbox and a line edit to display values.
The class is designed as a common super class for widgets likeQSpinBox,QDoubleSpinBox andQDateTimeEdit
Here are the main properties of the class:
QAbstractSpinBox provides a virtualstepBy() function that is called whenever the user triggers a step. This function takes an integer value to signify how many steps were taken. E.g. PressingQt::Key_Down will trigger a call tostepBy(-1).
QAbstractSpinBox also provide a virtual functionstepEnabled() to determine whether stepping up/down is allowed at any point. This function returns a bitset ofStepEnabled.
See alsoQAbstractSlider,QSpinBox,QDoubleSpinBox,QDateTimeEdit, andSpin Boxes Example.
This enum type describes the symbols that can be displayed on the buttons in a spin box.


| Constant | Value | Description |
|---|---|---|
QAbstractSpinBox::UpDownArrows | 0 | Little arrows in the classic style. |
QAbstractSpinBox::PlusMinus | 1 | + and- symbols. |
QAbstractSpinBox::NoButtons | 2 | Don't display buttons. |
See alsoQAbstractSpinBox::buttonSymbols.
This enum type describes the mode the spinbox will use to correct anIntermediate value if editing finishes.
| Constant | Value | Description |
|---|---|---|
QAbstractSpinBox::CorrectToPreviousValue | 0 | The spinbox will revert to the last valid value. |
QAbstractSpinBox::CorrectToNearestValue | 1 | The spinbox will revert to the nearest valid value. |
See alsocorrectionMode.
| Constant | Value |
|---|---|
QAbstractSpinBox::StepNone | 0x00 |
QAbstractSpinBox::StepUpEnabled | 0x01 |
QAbstractSpinBox::StepDownEnabled | 0x02 |
The StepEnabled type is a typedef forQFlags<StepEnabledFlag>. It stores an OR combination of StepEnabledFlag values.
This property holds whether the spin box will accelerate the frequency of the steps when pressing the step Up/Down buttons.
If enabled the spin box will increase/decrease the value faster the longer you hold the button down.
This property was introduced in Qt 4.2.
Access functions:
| bool | isAccelerated() const |
| void | setAccelerated(bool on) |
This property holds whether the input satisfies the current validation.
This property was introduced in Qt 4.2.
Access functions:
| bool | hasAcceptableInput() const |
See alsovalidate(),fixup(), andcorrectionMode.
This property holds the alignment of the spin box.
Possible Values areQt::AlignLeft,Qt::AlignRight, andQt::AlignHCenter.
By default, the alignment isQt::AlignLeft
Attempting to set the alignment to an illegal flag combination does nothing.
Access functions:
| Qt::Alignment | alignment() const |
| void | setAlignment(Qt::Alignment flag) |
See alsoQt::Alignment.
This property holds the current button symbol mode.
The possible values can be eitherUpDownArrows orPlusMinus. The default isUpDownArrows.
Note that some styles might renderPlusMinus andUpDownArrows identically.
Access functions:
| ButtonSymbols | buttonSymbols() const |
| void | setButtonSymbols(ButtonSymbols bs) |
See alsoButtonSymbols.
This property holds the mode to correct an Intermediate value if editing finishes.
The default mode isQAbstractSpinBox::CorrectToPreviousValue.
This property was introduced in Qt 4.2.
Access functions:
| CorrectionMode | correctionMode() const |
| void | setCorrectionMode(CorrectionMode cm) |
See alsoacceptableInput,validate(), andfixup().
This property holds whether the spin box draws itself with a frame.
If enabled (the default) the spin box draws itself inside a frame, otherwise the spin box draws itself without any frame.
Access functions:
| bool | hasFrame() const |
| void | setFrame(bool) |
This property holds whether keyboard tracking is enabled for the spinbox.
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.
This property was introduced in Qt 4.3.
Access functions:
| bool | keyboardTracking() const |
| void | setKeyboardTracking(bool kt) |
This property holds whether the spin box is read only.
In read-only mode, the user can still copy the text to the clipboard, or drag and drop the text; but cannot edit it.
TheQLineEdit in theQAbstractSpinBox does not show a cursor in read-only mode.
Access functions:
| bool | isReadOnly() const |
| void | setReadOnly(bool r) |
See alsoQLineEdit::readOnly.
This property holds the special-value text.
If set, the spin box will display this text instead of a numeric value whenever the current value is equal to minimum(). Typical use is to indicate that this choice has a special (default) meaning.
For example, if your spin box allows the user to choose a scale factor (or zoom level) for displaying an image, and your application is able to automatically choose one that will enable the image to fit completely within the display window, you can set up the spin box like this:
QSpinBox*zoomSpinBox=newQSpinBox; zoomSpinBox->setRange(0,1000); zoomSpinBox->setSingleStep(10); zoomSpinBox->setSuffix("%"); zoomSpinBox->setSpecialValueText(tr("Automatic")); zoomSpinBox->setValue(100);
The user will then be able to choose a scale from 1% to 1000% or select "Auto" to leave it up to the application to choose. Your code must then interpret the spin box value of 0 as a request from the user to scale the image to fit inside the window.
All values are displayed with the prefix and suffix (if set),except for the special value, which only shows the special value text. This special text is passed in theQSpinBox::valueChanged() signal that passes aQString.
To turn off the special-value text display, call this function with an empty string. The default is no special-value text, i.e. the numeric value is shown as usual.
If no special-value text is set, specialValueText() returns an empty string.
Access functions:
| QString | specialValueText() const |
| void | setSpecialValueText(const QString & txt) |
This property holds the spin box's text, including any prefix and suffix.
There is no default text.
Access functions:
| QString | text() const |
This property holds whether the spin box is circular.
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=newQSpinBox(this);spinBox->setRange(0,100);spinBox->setWrapping(true);spinBox->setValue(100);spinBox->stepBy(1);// value is 0
Access functions:
| bool | wrapping() const |
| void | setWrapping(bool w) |
See alsoQSpinBox::minimum() andQSpinBox::maximum().
Constructs an abstract spinbox with the givenparent with defaultwrapping, andalignment properties.
Called when theQAbstractSpinBox is destroyed.
[virtual protected]void QAbstractSpinBox::changeEvent(QEvent * event)Reimplemented fromQWidget::changeEvent().
[virtual slot]void QAbstractSpinBox::clear()Clears the lineedit of all text but prefix and suffix.
[virtual protected]void QAbstractSpinBox::closeEvent(QCloseEvent * event)Reimplemented fromQWidget::closeEvent().
[virtual protected]void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent * event)Reimplemented fromQWidget::contextMenuEvent().
[signal]void QAbstractSpinBox::editingFinished()This signal is emitted editing is finished. This happens when the spinbox loses focus and when enter is pressed.
[virtual]bool QAbstractSpinBox::event(QEvent * event)Reimplemented fromQObject::event().
[virtual]void QAbstractSpinBox::fixup(QString & input) constThis virtual function is called by theQAbstractSpinBox if theinput is not validated toQValidator::Acceptable when Return is pressed orinterpretText() is called. It will try to change the text so it is valid. Reimplemented in the various subclasses.
[virtual protected]void QAbstractSpinBox::focusInEvent(QFocusEvent * event)Reimplemented fromQWidget::focusInEvent().
[virtual protected]void QAbstractSpinBox::focusOutEvent(QFocusEvent * event)Reimplemented fromQWidget::focusOutEvent().
[virtual protected]void QAbstractSpinBox::hideEvent(QHideEvent * event)Reimplemented fromQWidget::hideEvent().
[protected]void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox * option) constInitializeoption with the values from thisQSpinBox. This method is useful for subclasses when they need aQStyleOptionSpinBox, but don't want to fill in all the information themselves.
See alsoQStyleOption::initFrom().
[virtual]QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) constReimplemented fromQWidget::inputMethodQuery().
This function interprets the text of the spin box. If the value has changed since last interpretation it will emit signals.
[virtual protected]void QAbstractSpinBox::keyPressEvent(QKeyEvent * event)Reimplemented fromQWidget::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 invokestepBy(1) |
| Down | This will invokestepBy(-1) |
| Page up | This will invokestepBy(10) |
| Page down | This will invokestepBy(-10) |
[virtual protected]void QAbstractSpinBox::keyReleaseEvent(QKeyEvent * event)Reimplemented fromQWidget::keyReleaseEvent().
[protected]QLineEdit * QAbstractSpinBox::lineEdit() constThis function returns a pointer to the line edit of the spin box.
See alsosetLineEdit().
[virtual]QSize QAbstractSpinBox::minimumSizeHint() constReimplemented fromQWidget::minimumSizeHint().
[virtual protected]void QAbstractSpinBox::mouseMoveEvent(QMouseEvent * event)Reimplemented fromQWidget::mouseMoveEvent().
[virtual protected]void QAbstractSpinBox::mousePressEvent(QMouseEvent * event)Reimplemented fromQWidget::mousePressEvent().
[virtual protected]void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent * event)Reimplemented fromQWidget::mouseReleaseEvent().
[virtual protected]void QAbstractSpinBox::paintEvent(QPaintEvent * event)Reimplemented fromQWidget::paintEvent().
[virtual protected]void QAbstractSpinBox::resizeEvent(QResizeEvent * event)Reimplemented fromQWidget::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 belineEdit instead of the current line edit widget.lineEdit can not be 0.
QAbstractSpinBox takes ownership of the newlineEdit
IfQLineEdit::validator() for thelineEdit returns 0, the internal validator of the spinbox will be set on the line edit.
See alsolineEdit().
[virtual protected]void QAbstractSpinBox::showEvent(QShowEvent * event)Reimplemented fromQWidget::showEvent().
[virtual]QSize QAbstractSpinBox::sizeHint() constReimplemented fromQWidget::sizeHint().
[virtual]void QAbstractSpinBox::stepBy(int steps)Virtual function that is called whenever the user triggers a step. Thesteps parameter indicates how many steps were taken, e.g. PressingQt::Key_Down will trigger a call to stepBy(-1), whereas pressingQt::Key_Prior will trigger a call to stepBy(10).
If you subclassQAbstractSpinBox 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 callingstepBy(-1);
[virtual protected]StepEnabled QAbstractSpinBox::stepEnabled() constVirtual 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 returnStepDownEnabled if value is > minimum() or'ed withStepUpEnabled if value < maximum().
If you subclassQAbstractSpinBox you will need to reimplement this function.
See alsoQSpinBox::minimum(),QSpinBox::maximum(), andwrapping().
[slot]void QAbstractSpinBox::stepUp()Steps up by one linestep Calling this slot is analogous to callingstepBy(1);
See alsostepBy() andstepDown().
[virtual protected]void QAbstractSpinBox::timerEvent(QTimerEvent * event)Reimplemented fromQObject::timerEvent().
[virtual]QValidator::State QAbstractSpinBox::validate(QString & input,int & pos) constThis virtual function is called by theQAbstractSpinBox to determine whetherinput is valid. Thepos parameter indicates the position in the string. Reimplemented in the various subclasses.
[virtual protected]void QAbstractSpinBox::wheelEvent(QWheelEvent * event)Reimplemented fromQWidget::wheelEvent().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.