QAbstractSpinBox Class
The QAbstractSpinBox class is the base of the widgets that show a value in a text with two buttons that step it. More…
| Header | #include <QAbstractSpinBox> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
| Inherited by | QDateTimeEdit, QDoubleSpinBox, QSpinBox |
List of all members, including inherited members
Public Types
| enum | StepEnabledFlag |
| typedef | StepEnabled |
Public Functions
| QAbstractSpinBox(QWidget *parent = nullptr) | |
| ~QAbstractSpinBox() | |
| QString | text() const |
| QString | specialValueText() const |
| void | setSpecialValueText(const QString &text) |
| bool | wrapping() const |
| void | setWrapping(bool wrapping) |
| bool | isReadOnly() const |
| void | setReadOnly(bool readOnly) |
| bool | keyboardTracking() const |
| void | setKeyboardTracking(bool enable) |
| void | interpretText() |
| virtual void | stepBy(int steps) |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Public Slots
Signals
| void | editingFinished() |
Protected Functions
| virtual StepEnabled | stepEnabled() const |
| QLineEdit * | lineEdit() const |
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
| void | resizeEvent(QResizeEvent *event) |
| void | mousePressEvent(QMouseEvent *event) |
| void | mouseReleaseEvent(QMouseEvent *event) |
| void | wheelEvent(QWheelEvent *event) |
| void | keyPressEvent(QKeyEvent *event) |
| void | changeEvent(QEvent *event) |
Detailed Description
A spin box has a line edit and a button to step up and one to step down. The arrow keys, Page Up and Page Down, and the mouse wheel step too. QSpinBox holds an integer and QDoubleSpinBox a floating-point number; a subclass of QAbstractSpinBox that holds another kind of value reimplements stepBy() and stepEnabled().
When the value is the smallest, the spin box can show a word instead of the number:
QSpinBox *delay = new QSpinBox(window);
delay->setRange(0, 60);
delay->setSuffix(" s");
delay->setSpecialValueText("Off");
See also QSpinBox and QDoubleSpinBox.
Differences from Qt
There is no alignment, buttonSymbols, accelerated, correctionMode, frame or showGroupSeparator, and no validate() or fixup(): the subclasses check what the user types. The buttons do not repeat while they are held. A subclass outside Nt can reimplement stepBy() and stepEnabled(), but the text is always that of a QSpinBox or a QDoubleSpinBox.
Member Type Documentation
typedef QAbstractSpinBox::StepEnabled
The StepEnabled type is a typedef for QFlags<StepEnabledFlag>. It stores an OR combination of StepEnabledFlag values.
enum QAbstractSpinBox::StepEnabledFlag
Which ways the spin box can step, as returned by stepEnabled().
| Constant | Description |
|---|---|
QAbstractSpinBox::StepNone | Neither. |
QAbstractSpinBox::StepUpEnabled | Up. |
QAbstractSpinBox::StepDownEnabled | Down. |
Member Function Documentation
QAbstractSpinBox::QAbstractSpinBox(QWidget *parent = nullptr)
Constructs a spin box with the given parent.
QAbstractSpinBox::~QAbstractSpinBox()
Destroys the spin box.
void QAbstractSpinBox::changeEvent(QEvent *event)
Reimplements QWidget::changeEvent().
void QAbstractSpinBox::clear()
Clears the text but for the prefix and the suffix. The value does not change until the user types a new one.
void QAbstractSpinBox::editingFinished()
This signal is emitted when the user has finished editing the text: Return or Enter is pressed, or the spin box loses the focus.
void QAbstractSpinBox::interpretText()
Takes the text that the user typed as the value, as when editing finishes, without emitting editingFinished().
bool QAbstractSpinBox::isReadOnly() const
Returns whether the user cannot change the value. The default is false.
See also setReadOnly().
bool QAbstractSpinBox::keyboardTracking() const
Returns whether the value follows the text as the user types. The default is true.
See also setKeyboardTracking().
void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
Reimplements QWidget::keyPressEvent().
Up and Down step by one single step, Page Up and Page Down by ten.
QLineEdit * QAbstractSpinBox::lineEdit() const
Returns the line edit that shows the text.
QSize QAbstractSpinBox::minimumSizeHint() const
Reimplements QWidget::minimumSizeHint().
void QAbstractSpinBox::mousePressEvent(QMouseEvent *event)
Reimplements QWidget::mousePressEvent().
void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event)
Reimplements QWidget::mouseReleaseEvent().
void QAbstractSpinBox::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
void QAbstractSpinBox::resizeEvent(QResizeEvent *event)
Reimplements QWidget::resizeEvent().
void QAbstractSpinBox::selectAll()
Selects the text between the prefix and the suffix.
void QAbstractSpinBox::setKeyboardTracking(bool enable)
Sets whether the value follows the text as the user types to enable. Without it, the value changes when the user presses Return or the spin box loses the focus.
See also keyboardTracking().
void QAbstractSpinBox::setReadOnly(bool readOnly)
Sets whether the user cannot change the value to readOnly. A read-only spin box shows its value and lets the text be selected, but it does not step and its text cannot be edited.
See also isReadOnly().
void QAbstractSpinBox::setSpecialValueText(const QString &text)
Sets the text shown instead of the smallest value to text. Typing the text sets the smallest value. An empty text shows the number.
See also specialValueText().
void QAbstractSpinBox::setWrapping(bool wrapping)
Sets whether stepping past one end goes round to the other to wrapping.
See also wrapping().
QSize QAbstractSpinBox::sizeHint() const
Reimplements QWidget::sizeHint().
QString QAbstractSpinBox::specialValueText() const
Returns the text that is shown instead of the smallest value, or an empty string if the number is shown.
See also setSpecialValueText().
void QAbstractSpinBox::stepBy(int steps)
Steps the value by steps single steps, up if steps is positive. The default implementation does nothing; QSpinBox and QDoubleSpinBox reimplement it.
See also stepUp(), stepDown() and stepEnabled().
void QAbstractSpinBox::stepDown()
Steps the value down by one single step.
See also stepBy().
StepEnabled QAbstractSpinBox::stepEnabled() const
Returns which ways the spin box can step. The default implementation returns StepNone for a read-only spin box and both ways otherwise; QSpinBox and QDoubleSpinBox look at the value and the range.
See also stepBy().
void QAbstractSpinBox::stepUp()
Steps the value up by one single step.
See also stepBy().
QString QAbstractSpinBox::text() const
Returns the text of the spin box: the value with the prefix and the suffix, or what the user is typing.
See also QSpinBox::cleanText().
void QAbstractSpinBox::wheelEvent(QWheelEvent *event)
Reimplements QWidget::wheelEvent().
bool QAbstractSpinBox::wrapping() const
Returns whether stepping past one end goes round to the other. The default is false.
See also setWrapping().