QAbstractSpinBox露
The
QAbstractSpinBoxclass provides a spinbox and a line edit to display values. More鈥

Inherited by: QDateEdit, QDateTimeEdit, QDoubleSpinBox, QSpinBox, QTimeEdit
Synopsis露
Functions露
def
alignment()def
buttonSymbols()def
correctionMode()def
hasAcceptableInput()def
hasFrame()def
initStyleOption(option)def
interpretText()def
isAccelerated()def
isGroupSeparatorShown()def
isReadOnly()def
keyboardTracking()def
lineEdit()def
setAccelerated(on)def
setAlignment(flag)def
setButtonSymbols(bs)def
setCorrectionMode(cm)def
setFrame(arg__1)def
setGroupSeparatorShown(shown)def
setKeyboardTracking(kt)def
setLineEdit(edit)def
setReadOnly(r)def
setSpecialValueText(txt)def
setWrapping(w)def
specialValueText()def
text()def
wrapping()
Virtual functions露
def
clear()def
fixup(input)def
stepBy(steps)def
stepEnabled()def
validate(input, pos)
Slots露
Signals露
def
editingFinished()
Detailed Description露
The class is designed as a common super class for widgets like
QSpinBox,QDoubleSpinBoxandQDateTimeEditHere are the main properties of the class:
text: The text that is displayed in theQAbstractSpinBox.alignment : The alignment of the text in the
QAbstractSpinBox.
wrapping: Whether theQAbstractSpinBoxwraps from the minimum value to the maximum value and vice versa.
QAbstractSpinBoxprovides 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. PressingKey_Downwill trigger a call tostepBy(-1).When the user triggers a step whilst holding the
ControlModifier,QAbstractSpinBoxsteps by 10 instead of making a single step. This step modifier affects wheel events, key events and interaction with the spinbox buttons. Note that on macOS, Control corresponds to the Command key.Since Qt 5.12,
SH_SpinBox_StepModifiercan be used to select whichKeyboardModifierincreases the step rate.NoModifierdisables this feature.
QAbstractSpinBoxalso provide a virtual functionstepEnabled()to determine whether stepping up/down is allowed at any point. This function returns a bitset ofStepEnabled.
- class PySide2.QtWidgets.QAbstractSpinBox([parent=None])露
- param parent:
Constructs an abstract spinbox with the given
parentwith defaultwrapping, and alignment properties.
- PySide2.QtWidgets.QAbstractSpinBox.StepEnabledFlag露
Constant
Description
QAbstractSpinBox.StepNone
QAbstractSpinBox.StepUpEnabled
QAbstractSpinBox.StepDownEnabled
- PySide2.QtWidgets.QAbstractSpinBox.ButtonSymbols露
This enum type describes the symbols that can be displayed on the buttons in a spin box.

Constant
Description
QAbstractSpinBox.UpDownArrows
Little arrows in the classic style.
QAbstractSpinBox.PlusMinus
+ and - symbols.
QAbstractSpinBox.NoButtons
Don鈥檛 display buttons.
See also
- PySide2.QtWidgets.QAbstractSpinBox.CorrectionMode露
This enum type describes the mode the spinbox will use to correct an
Intermediatevalue if editing finishes.Constant
Description
QAbstractSpinBox.CorrectToPreviousValue
The spinbox will revert to the last valid value.
QAbstractSpinBox.CorrectToNearestValue
The spinbox will revert to the nearest valid value.
See also
- PySide2.QtWidgets.QAbstractSpinBox.StepType露
Constant
Description
QAbstractSpinBox.DefaultStepType
QAbstractSpinBox.AdaptiveDecimalStepType
New in version 5.12.
- PySide2.QtWidgets.QAbstractSpinBox.alignment()露
- Return type:
Alignment
This property holds the alignment of the spin box.
Possible Values are
AlignLeft,AlignRight, andAlignHCenter.By default, the alignment is
AlignLeftAttempting to set the alignment to an illegal flag combination does nothing.
See also
Alignment
- PySide2.QtWidgets.QAbstractSpinBox.buttonSymbols()露
- Return type:
This property holds the current button symbol mode.
The possible values can be either
UpDownArrowsorPlusMinus. The default isUpDownArrows.Note that some styles might render
PlusMinusandUpDownArrowsidentically.See also
ButtonSymbols
- PySide2.QtWidgets.QAbstractSpinBox.clear()露
Clears the lineedit of all text but prefix and suffix.
- PySide2.QtWidgets.QAbstractSpinBox.correctionMode()露
- Return type:
This property holds the mode to correct an
Intermediatevalue if editing finishes.The default mode is
CorrectToPreviousValue.See also
acceptableInputvalidate()fixup()
- PySide2.QtWidgets.QAbstractSpinBox.editingFinished()露
- PySide2.QtWidgets.QAbstractSpinBox.fixup(input)露
- Parameters:
input 鈥 str
This virtual function is called by the
QAbstractSpinBoxif theinputis not validated toAcceptablewhen Return is pressed orinterpretText()is called. It will try to change the text so it is valid. Reimplemented in the various subclasses.
- PySide2.QtWidgets.QAbstractSpinBox.hasAcceptableInput()露
- Return type:
bool
This property holds whether the input satisfies the current validation.
See also
- PySide2.QtWidgets.QAbstractSpinBox.hasFrame()露
- Return type:
bool
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.
- PySide2.QtWidgets.QAbstractSpinBox.initStyleOption(option)露
- Parameters:
Initialize
optionwith the values from thisQSpinBox. This method is useful for subclasses when they need aQStyleOptionSpinBox, but don鈥檛 want to fill in all the information themselves.See also
- PySide2.QtWidgets.QAbstractSpinBox.interpretText()露
This function interprets the text of the spin box. If the value has changed since last interpretation it will emit signals.
- PySide2.QtWidgets.QAbstractSpinBox.isAccelerated()露
- Return type:
bool
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.
- PySide2.QtWidgets.QAbstractSpinBox.isGroupSeparatorShown()露
- Return type:
bool
This property holds whether a thousands separator is enabled. By default this property is false.
- PySide2.QtWidgets.QAbstractSpinBox.isReadOnly()露
- Return type:
bool
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.
The
QLineEditin theQAbstractSpinBoxdoes not show a cursor in read-only mode.See also
readOnly
- PySide2.QtWidgets.QAbstractSpinBox.keyboardTracking()露
- Return type:
bool
This property holds whether keyboard tracking is enabled for the spinbox..
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鈥檛 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.
- PySide2.QtWidgets.QAbstractSpinBox.lineEdit()露
- Return type:
This function returns a pointer to the line edit of the spin box.
See also
- PySide2.QtWidgets.QAbstractSpinBox.selectAll()露
Selects all the text in the spinbox except the prefix and suffix.
- PySide2.QtWidgets.QAbstractSpinBox.setAccelerated(on)露
- Parameters:
on 鈥 bool
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.
- PySide2.QtWidgets.QAbstractSpinBox.setAlignment(flag)露
- Parameters:
flag 鈥
Alignment
This property holds the alignment of the spin box.
Possible Values are
AlignLeft,AlignRight, andAlignHCenter.By default, the alignment is
AlignLeftAttempting to set the alignment to an illegal flag combination does nothing.
See also
Alignment
- PySide2.QtWidgets.QAbstractSpinBox.setButtonSymbols(bs)露
- Parameters:
bs 鈥
ButtonSymbols
This property holds the current button symbol mode.
The possible values can be either
UpDownArrowsorPlusMinus. The default isUpDownArrows.Note that some styles might render
PlusMinusandUpDownArrowsidentically.See also
ButtonSymbols
- PySide2.QtWidgets.QAbstractSpinBox.setCorrectionMode(cm)露
- Parameters:
cm 鈥
CorrectionMode
This property holds the mode to correct an
Intermediatevalue if editing finishes.The default mode is
CorrectToPreviousValue.See also
acceptableInputvalidate()fixup()
- PySide2.QtWidgets.QAbstractSpinBox.setFrame(arg__1)露
- Parameters:
arg__1 鈥 bool
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.
- PySide2.QtWidgets.QAbstractSpinBox.setGroupSeparatorShown(shown)露
- Parameters:
shown 鈥 bool
This property holds whether a thousands separator is enabled. By default this property is false.
- PySide2.QtWidgets.QAbstractSpinBox.setKeyboardTracking(kt)露
- Parameters:
kt 鈥 bool
This property holds whether keyboard tracking is enabled for the spinbox..
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鈥檛 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.
- PySide2.QtWidgets.QAbstractSpinBox.setLineEdit(edit)露
- Parameters:
edit 鈥
PySide2.QtWidgets.QLineEdit
Sets the line edit of the spinbox to be
lineEditinstead of the current line edit widget.lineEditcannot beNone.QAbstractSpinBoxtakes ownership of the newlineEditIf
validator()for thelineEditreturnsNone, the internal validator of the spinbox will be set on the line edit.See also
- PySide2.QtWidgets.QAbstractSpinBox.setReadOnly(r)露
- Parameters:
r 鈥 bool
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.
The
QLineEditin theQAbstractSpinBoxdoes not show a cursor in read-only mode.See also
readOnly
- PySide2.QtWidgets.QAbstractSpinBox.setSpecialValueText(txt)露
- Parameters:
txt 鈥 str
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:
zoomSpinBox = QSpinBox() 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 鈥淎uto鈥 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 the
textChanged()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, returns an empty string.
- PySide2.QtWidgets.QAbstractSpinBox.setWrapping(w)露
- Parameters:
w 鈥 bool
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 vice versa. Wrapping only make sense if you have minimum() and maximum() values set.
spinBox = QSpinBox(self) spinBox.setRange(0, 100) spinBox.setWrapping(True) spinBox.setValue(100) spinBox.stepBy(1) // value is 0
- PySide2.QtWidgets.QAbstractSpinBox.specialValueText()露
- Return type:
str
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:
zoomSpinBox = QSpinBox() 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 鈥淎uto鈥 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 the
textChanged()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, returns an empty string.
- PySide2.QtWidgets.QAbstractSpinBox.stepBy(steps)露
- Parameters:
steps 鈥 int
Virtual function that is called whenever the user triggers a step. The
stepsparameter indicates how many steps were taken. For example, pressingQt::Key_Downwill trigger a call tostepBy(-1), whereas pressingQt::Key_PageUpwill trigger a call tostepBy(10).If you subclass
QAbstractSpinBoxyou 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鈥檚 this function鈥檚 job to handle these situations.See also
stepUp()stepDown()keyPressEvent()
- PySide2.QtWidgets.QAbstractSpinBox.stepDown()露
Steps down by one linestep Calling this slot is analogous to calling
stepBy(-1);
- PySide2.QtWidgets.QAbstractSpinBox.stepEnabled()露
- Return type:
StepEnabled
Virtual function that determines whether stepping up and down is legal at any given time.
The up arrow will be painted as disabled unless ( &
StepUpEnabled) != 0.The default implementation will return (
StepUpEnabled|StepDownEnabled) if wrapping is turned on. Else it will returnStepDownEnabledif value is > minimum() or鈥檈d withStepUpEnabledif value < maximum().If you subclass
QAbstractSpinBoxyou will need to reimplement this function.See also
- PySide2.QtWidgets.QAbstractSpinBox.stepUp()露
Steps up by one linestep Calling this slot is analogous to calling
stepBy(1);See also
- PySide2.QtWidgets.QAbstractSpinBox.text()露
- Return type:
str
This property holds the spin box鈥檚 text, including any prefix and suffix.
There is no default text.
- PySide2.QtWidgets.QAbstractSpinBox.validate(input, pos)露
- Parameters:
input 鈥 str
pos 鈥 int
- Return type:
PyObject
This virtual function is called by the
QAbstractSpinBoxto determine whetherinputis valid. Theposparameter indicates the position in the string. Reimplemented in the various subclasses.
- PySide2.QtWidgets.QAbstractSpinBox.wrapping()露
- Return type:
bool
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 vice versa. Wrapping only make sense if you have minimum() and maximum() values set.
spinBox = QSpinBox(self) spinBox.setRange(0, 100) spinBox.setWrapping(True) spinBox.setValue(100) spinBox.stepBy(1) // value is 0
漏 2022 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 the GNU 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.