CopperSpice API  1.9.2
QSpinBox Class Reference

The QSpinBox class provides a spin box widget. More...

Inheritance diagram for QSpinBox:
QAbstractSpinBox QWidget QObject QPaintDevice

Public Signals

void valueChanged (const QString &text)
 
void valueChanged (int newValue)
 
- Public Signals inherited from QAbstractSpinBox
void editingFinished ()
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setValue (int val)
 
- Public Slots inherited from QAbstractSpinBox
virtual void clear ()
 
void selectAll ()
 
void stepDown ()
 
void stepUp ()
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QSpinBox (QWidget *parent=nullptr)
 
QString cleanText () const
 
int displayIntegerBase () const
 
int maximum () const
 
int minimum () const
 
QString prefix () const
 
void setDisplayIntegerBase (int base)
 
void setMaximum (int max)
 
void setMinimum (int min)
 
void setPrefix (const QString &prefix)
 
void setRange (int min, int max)
 
void setSingleStep (int val)
 
void setSuffix (const QString &suffix)
 
int singleStep () const
 
QString suffix () const
 
int value () const
 
- Public Methods inherited from QAbstractSpinBox
 QAbstractSpinBox (QWidget *parent=nullptr)
 
 ~QAbstractSpinBox ()
 
Qt::Alignment alignment () const
 
ButtonSymbols buttonSymbols () const
 
CorrectionMode correctionMode () const
 
bool event (QEvent *event) override
 
bool hasAcceptableInput () const
 
bool hasFrame () const
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const override
 
void interpretText ()
 
bool isAccelerated () const
 
bool isGroupSeparatorShown () const
 
bool isReadOnly () const
 
bool keyboardTracking () const
 
QSize minimumSizeHint () const override
 
void setAccelerated (bool on)
 
void setAlignment (Qt::Alignment flag)
 
void setButtonSymbols (ButtonSymbols symbols)
 
void setCorrectionMode (CorrectionMode cm)
 
void setFrame (bool enable)
 
void setGroupSeparatorShown (bool shown)
 
void setKeyboardTracking (bool enable)
 
void setReadOnly (bool enable)
 
void setSpecialValueText (const QString &txt)
 
void setWrapping (bool wrapping)
 
QSize sizeHint () const override
 
QString specialValueText () const
 
virtual void stepBy (int steps)
 
QString text () const
 
bool wrapping () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

bool event (QEvent *event) override
 
void fixup (QString &input) const override
 
virtual QString textFromValue (int value) const
 
QValidator::State validate (QString &input, int &pos) const override
 
virtual int valueFromText (const QString &text) const
 
- Protected Methods inherited from QAbstractSpinBox
void changeEvent (QEvent *event) override
 
void closeEvent (QCloseEvent *event) override
 
void contextMenuEvent (QContextMenuEvent *event) override
 
void focusInEvent (QFocusEvent *event) override
 
void focusOutEvent (QFocusEvent *event) override
 
void hideEvent (QHideEvent *event) override
 
void initStyleOption (QStyleOptionSpinBox *option) const
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
QLineEditlineEdit () const
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void setLineEdit (QLineEdit *lineEdit)
 
void showEvent (QShowEvent *event) override
 
virtual StepEnabled stepEnabled () const
 
void timerEvent (QTimerEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
bool focusPreviousChild ()
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void tabletEvent (QTabletEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 cleanText
 
 displayIntegerBase
 
 maximum
 
 minimum
 
 prefix
 
 singleStep
 
 suffix
 
 value
 
- Properties inherited from QAbstractSpinBox
 accelerated
 
 acceptableInput
 
 alignment
 
 buttonSymbols
 
 correctionMode
 
 frame
 
 keyboardTracking
 
 readOnly
 
 specialValueText
 
 text
 
 wrapping
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QAbstractSpinBox
using StepEnabled = QFlags< StepEnabledFlag >
 
- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Public Types inherited from QAbstractSpinBox
enum  ButtonSymbols
 
enum  CorrectionMode
 
enum  StepEnabledFlag
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QSpinBox class provides a spin box widget designed to handle integers and discrete sets of values like month names. Use QDoubleSpinBox for floating point values.

QSpinBox allows the user to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the value currently displayed. The user can also type the value in manually. The spin box supports integer values but can be extended to use different strings with validate(), textFromValue() and valueFromText().

Every time the value changes QSpinBox emits the valueChanged() signals. The current value can be fetched with value() and set with setValue().

Clicking the up/down buttons or using the keyboard accelerator's up and down arrows will increase or decrease the current value in steps of size singleStep(). If you want to change this behavior you can reimplement the virtual function stepBy(). The minimum and maximum value and the step size can be set using one of the constructors, and can be changed later with setMinimum(), setMaximum() and setSingleStep().

Most spin boxes are directional, but QSpinBox can also operate as a circular spin box, i.e. if the range is 0-99 and the current value is 99, clicking "up" will give 0 if wrapping() is set to true. Use setWrapping() if you want circular behavior.

The displayed value can be prepended and appended with arbitrary strings indicating, for example, currency or the unit of measurement. See setPrefix() and setSuffix(). The text in the spin box is retrieved with text() (which includes any prefix() and suffix()), or with cleanText() (which has no prefix(), no suffix() and no leading or trailing whitespace).

It is often desirable to give user a default value in addition to the range of acceptable numeric values. Refer to the setSpecialValueText() method for more information.

Screenshot of a Windows XP spin box Spin box shown in the Windows XP widget style.
Screenshot of a Mac OS X spin box Spin box shown in the Mac OS X widget style.
Screenshot of a Fusion spin box Spin box shown in the Fusion widget style.

Subclassing QSpinBox

If using prefix(), suffix(), and specialValueText() do not provide enough control you subclass QSpinBox and reimplement valueFromText() and textFromValue(). The following example show code for a custom spin box which allows the user to enter icon sizes such as "32 x 32".

int IconSizeSpinBox::valueFromText(const QString &text) const {
QRegularExpression regExp(tr("(\\d+)(\\s*x\\s*\\d+)?"), QPatternOption::ExactMatchOption);
if (match.hasMatch())) {
return regExp.captured(1).toInteger<int>();
} else {
return 0;
}
}
QString IconSizeSpinBox::textFromValue(int value) const {
return tr("%1 x %1").formatArg(value);
}
See also
QDoubleSpinBox, QDateTimeEdit, QSlider

Constructor & Destructor Documentation

QSpinBox::QSpinBox ( QWidget parent = nullptr)
explicit

Constructs a spin box with the given parent. The minimum value is 0 and the maximum value is 99, using a step value of 1. The value of the QSpinbox is initially set to 0.

See also
setMinimum(), setMaximum(), setSingleStep()

Method Documentation

QString QSpinBox::cleanText ( ) const

Returns the value of the property.

int QSpinBox::displayIntegerBase ( ) const

Returns the value of the property.

bool QSpinBox::event ( QEvent event)
overrideprotected

Reimplemented from QAbstractSpinBox::event()

void QSpinBox::fixup ( QString input) const
overrideprotectedvirtual

Reimplemented from QAbstractSpinBox::fixup()

int QSpinBox::maximum ( ) const

Returns the value of the property.

int QSpinBox::minimum ( ) const

Returns the value of the property.

QString QSpinBox::prefix ( ) const

Returns the value of the property.

void QSpinBox::setDisplayIntegerBase ( int  base)

Sets the value of the property to base.

void QSpinBox::setMaximum ( int  max)

Sets the value of the property to max.

void QSpinBox::setMinimum ( int  min)

Sets the value of the property to min.

void QSpinBox::setPrefix ( const QString prefix)

Sets the value of the property to prefix.

void QSpinBox::setRange ( int  min,
int  max 
)

This method is used to set the min and max values with a single call.

setRange(min, max);
// equivalent to calling
See also
QSpinBox::minimum, QSpinBox::maximum
void QSpinBox::setSingleStep ( int  val)

Sets the value of the property to val.

void QSpinBox::setSuffix ( const QString suffix)

Sets the value of the property to suffix.

void QSpinBox::setValue ( int  val)
slot

Sets the value of the property to val.

int QSpinBox::singleStep ( ) const

Returns the value of the property.

QString QSpinBox::suffix ( ) const

Returns the value of the property.

QString QSpinBox::textFromValue ( int  value) const
protectedvirtual

This method is used by the spin box when it needs to display the given value. The default implementation returns a string containing value using QWidget::locale().toString(), but with the thousand separator removed.

If you reimplement this method you may also need to reimplement valueFromText() and validate(). QSpinBox does not call this method in the implementation of specialValueText(). This method should not return a value which includes the prefix() or suffix().

See also
valueFromText(), validate(), QLocale::groupSeparator()
QValidator::State QSpinBox::validate ( QString input,
int &  pos 
) const
overrideprotectedvirtual

Reimplemented from QAbstractSpinBox::validate()

int QSpinBox::value ( ) const

Returns the value of the property.

void QSpinBox::valueChanged ( const QString text)
signal

This signal is emitted when the spin box value is changed. The new value for the spin box is the given text with no prefix() or suffix().

void QSpinBox::valueChanged ( int  newValue)
signal

This signal is emitted when the spin box value is changed. The new value for the spin box is the given newValue.

int QSpinBox::valueFromText ( const QString text) const
protectedvirtual

This method is used by the spin box whenever it needs to interpret text entered by the user as a value. Subclasses that need to display spin box values in a non-numeric way need to reimplement this function.

QSpinBox handles specialValueText() separately; this function is only concerned with the other values.

See also
textFromValue(), validate()

Property Documentation

QSpinBox::cleanText

This property holds the text of the spin box excluding any prefix, suffix, or leading or trailing whitespace.

See also
text, QSpinBox::prefix, QSpinBox::suffix
PropertiesClass Methods
read cleanText
QSpinBox::displayIntegerBase

This property holds the base used to display the value of the spin box. The default displayIntegerBase value is 10.

See also
textFromValue(), valueFromText()
PropertiesClass Methods
read displayIntegerBase
write setDisplayIntegerBase
QSpinBox::maximum

This property holds the maximum value of the spin box. When setting this property the minimum is adjusted if necessary, to ensure that the range remains valid. The default maximum value is 99.

See also
setRange(), specialValueText
PropertiesClass Methods
read maximum
write setMaximum
QSpinBox::minimum

This property holds the minimum value of the spin box. When setting this property the maximum is adjusted if necessary to ensure that the range remains valid. The default minimum value is 0.

See also
setRange(), specialValueText
PropertiesClass Methods
read minimum
write setMinimum
QSpinBox::prefix

This property holds the spin box's prefix. The prefix is prepended to the start of the displayed value. Typical use is to display a unit of measurement or a currency symbol.

sb->setPrefix("$");

To turn off the prefix display, set this property to an empty string. The default is no prefix. The prefix is not displayed when value() == minimum() and specialValueText() is set.

If no prefix is set, prefix() returns an empty string.

See also
suffix(), setSuffix(), specialValueText(), setSpecialValueText()
PropertiesClass Methods
read prefix
write setPrefix
QSpinBox::singleStep

This property holds the step value.

When the user uses the arrows to change the spin box's value the value will be incremented/decremented by the amount of the singleStep. The default value is 1. Setting a singleStep value of less than 0 does nothing.

PropertiesClass Methods
read singleStep
write setSingleStep
QSpinBox::suffix

This property holds the suffix of the spin box. The suffix is appended to the end of the displayed value. Typical use is to display a unit of measurement or a currency symbol.

sb->setSuffix(" km");

To turn off the suffix display, set this property to an empty string. The default is no suffix. The suffix is not displayed for the minimum() if specialValueText() is set. If no suffix is set suffix() returns an empty string.

See also
prefix(), setPrefix(), specialValueText(), setSpecialValueText()
PropertiesClass Methods
read suffix
write setSuffix
QSpinBox::value

This property holds the value of the spin box.

setValue() will emit valueChanged() if the new value is different from the old one.

PropertiesClass Methods
read value
write setValue
notify valueChanged
user true