QSpinBox(3qt)
QSpinBox(3qt) πβ¨
NAME
QSpinBox β spin box widget (spin button). That's the whole vibe. π
SYNOPSIS
Okay bestie, here's the include and the family tree:
#include <qspinbox.h>
Inherits QWidget and QRangeControl.
Public Members
QSpinBox ( QWidget * parent = 0, const char * name = 0 )QSpinBox ( int minValue, int maxValue, int step = 1, QWidget * parent = 0, const char * name = 0 )~QSpinBox ()QString text () constvirtual QString prefix () constvirtual QString suffix () constvirtual QString cleanText () constvirtual void setSpecialValueText ( const QString & text )QString specialValueText () constvirtual void setWrapping ( bool on )bool wrapping () constenum ButtonSymbols { UpDownArrows, PlusMinus }virtual void setButtonSymbols ( ButtonSymbols )ButtonSymbols buttonSymbols () constvirtual void setValidator ( const QValidator * v )const QValidator * validator () constint minValue () constint maxValue () constvoid setMinValue ( int )void setMaxValue ( int )int lineStep () constvoid setLineStep ( int )int value () constQRect upRect () constQRect downRect () const
Public Slots
virtual void setValue ( int value )virtual void setPrefix ( const QString & text )virtual void setSuffix ( const QString & text )virtual void stepUp ()virtual void stepDown ()virtual void selectAll ()
Signals
void valueChanged ( int value )void valueChanged ( const QString & valueText )
Properties
ButtonSymbols buttonSymbolsβ the current button symbol modeQString cleanTextβ the spin box's text with noprefix(),suffix()or leading or trailing whitespace (read only)int lineStepβ the line stepint maxValueβ the maximum value of the spin boxint minValueβ the minimum value of the spin boxQString prefixβ the spin box's prefixQString specialValueTextβ the special-value textQString suffixβ the suffix of the spin boxQString textβ the spin box's text, including anyprefix()andsuffix()(read only)int valueβ the value of the spin boxbool wrappingβ whether it is possible to step the value from the highest value to the lowest value and vice versa
Protected Members
virtual QString mapValueToText ( int v )virtual int mapTextToValue ( bool * ok )QString currentValueText ()virtual void updateDisplay ()virtual void interpretText ()QLineEdit * editor () constvirtual void valueChange ()virtual void rangeChange ()virtual bool eventFilter ( QObject * o, QEvent * ev )
Protected Slots
void textChanged ()
DESCRIPTION π
The QSpinBox class provides a spin box widget (spin button). It's giving "choose a number, bestie" energy.
QSpinBox lets the user pick a value either by clicking the up/down buttons to increase/decrease the value currently displayed, or by typing the value directly into the spin box. If you type it in directly, you gotta hit Enter (or Return) to apply that new value. The value is usually an integer. No cap.
Every time the value changes, QSpinBox emits the valueChanged() signal. You can grab the current value with value() and set it with setValue(). Iconic.
The spin box keeps the value within a numeric range, and to multiples of the lineStep() size (peep QRangeControl for details). 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 lineStep(). You can set the minimum and maximum value and the step size using one of the constructors, and change them later with setMinValue(), setMaxValue() and setLineStep(). Slay.
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. Use setWrapping() if you want that circular behavior. It's a whole loop. π
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). currentValueText() returns the spin box's current value as text. So many text options, I know. π
Normally the spin box displays up and down arrows in the buttons. You can use setButtonSymbols() to change the display to show + and - symbols if you prefer. In either case the up and down arrow keys work as expected. Periodt.
It is often desirable to give the user a special (often default) choice in addition to the range of numeric values. See setSpecialValueText() for how to do this with QSpinBox. It's the "Auto" option of your dreams.
The default QWidget::focusPolicy() is StrongFocus.
If using prefix(), suffix() and specialValueText() don't provide enough control, you can ignore them and subclass QSpinBox instead. Go off, subclass.
QSpinBox can easily be subclassed to allow the user to input things other than an integer value as long as the allowed input can be mapped to a range of integers. This can be done by overriding the virtual functions mapValueToText() and mapTextToValue(), and setting another suitable validator using setValidator().
For example, these functions could be changed so that the user provided values from 0.0 to 10.0, or -1 to signify 'Auto', while the range of integers used inside the program would be -1 to 100:
class MySpinBox : public QSpinBox
{
Q_OBJECT
public:
...
QString mapValueToText( int value )
{
if ( value == -1 ) // special case
return QString( "Auto" );
return QString( "%1.%2" ) // 0.0 to 10.0
.arg( value / 10 ).arg( value % 10 );
}
int mapTextToValue( bool *ok )
{
if ( text() == "Auto" ) // special case
return -1;
return (int) ( 10 * text().toFloat() ); // 0 to 100
}
};
[Image Omitted]
[Image Omitted]
See also QScrollBar, QSlider, GUI Design Handbook: Spin Box, and Basic Widgets.
Member Type Documentation π
QSpinBox::ButtonSymbols
This enum type determines what the buttons in a spin box show.
QSpinBox::UpDownArrowsβ the buttons show little arrows in the classic style.QSpinBox::PlusMinusβ the buttons show+and-symbols.
See also QSpinBox::buttonSymbols.
MEMBER FUNCTION DOCUMENTATION π
QSpinBox::QSpinBox ( QWidget * parent = 0, const char * name = 0 )
Constructs a spin box with the default QRangeControl range and step values. It is called name and has parent parent.
See also minValue, maxValue, setRange(), lineStep, and setSteps().
QSpinBox::QSpinBox ( int minValue, int maxValue, int step = 1, QWidget * parent = 0, const char * name = 0 )
Constructs a spin box that allows values from minValue to maxValue inclusive, with step amount step. The value is initially set to minValue.
The spin box is called name and has parent parent.
See also minValue, maxValue, setRange(), lineStep, and setSteps().
QSpinBox::~QSpinBox ()
Destroys the spin box, freeing all memory and other resources. Rip, but make it clean. π§Ή
ButtonSymbols QSpinBox::buttonSymbols () const
Returns the current button symbol mode. See the "buttonSymbols" property for details.
QString QSpinBox::cleanText () const [virtual]
Returns the spin box's text with no prefix(), suffix() or leading or trailing whitespace. See the "cleanText" property for details.
QString QSpinBox::currentValueText () [protected]
Returns the full text calculated from the current value, including any prefix and suffix. If there is special value text and the value is minValue() the specialValueText() is returned.
QRect QSpinBox::downRect () const
Returns the geometry of the "down" button. The down button's rect. π
QLineEdit * QSpinBox::editor () const [protected]
Returns a pointer to the embedded QLineEdit.
bool QSpinBox::eventFilter ( QObject * o, QEvent * ev ) [virtual protected]
Intercepts and handles the events coming to the embedded QLineEdit that have special meaning for the QSpinBox. The object is passed as o and the event is passed as ev.
Reimplemented from QObject.
void QSpinBox::interpretText () [virtual protected]
QSpinBox calls this after the user has manually edited the contents of the spin box (i.e. by typing in the embedded QLineEdit, rather than using the up/down buttons/keys).
The default implementation of this function interprets the new text using mapTextToValue(). If mapTextToValue() is successful, it changes the spin box's value; if not, the value is left unchanged.
See also editor().
int QSpinBox::lineStep () const
Returns the line step. See the "lineStep" property for details.
int QSpinBox::mapTextToValue ( bool * ok ) [virtual protected]
This virtual function is used by the spin box whenever it needs to interpret text entered by the user as a value. The text is available as text() and as cleanText(), and this function must parse it if possible. If ok is not 0: if it parses the text successfully, *ok is set to TRUE; otherwise *ok is set to FALSE.
Subclasses that need to display spin box values in a non-numeric way need to reimplement this function.
Note that Qt handles specialValueText() separately; this function is only concerned with the other values.
The default implementation tries to interpret the text() as an integer in the standard way and returns the integer value.
See also interpretText() and mapValueToText().
QString QSpinBox::mapValueToText ( int v ) [virtual protected]
This virtual function is used by the spin box whenever it needs to display value v. The default implementation returns a string containing v printed in the standard way. Reimplementations may return anything. (See the example in the detailed description.)
Note that Qt does not call this function for specialValueText() and that neither prefix() nor suffix() are included in the return value.
If you reimplement this, you may also need to reimplement mapTextToValue().
See also updateDisplay() and mapTextToValue().
int QSpinBox::maxValue () const
Returns the maximum value of the spin box. See the "maxValue" property for details.
int QSpinBox::minValue () const
Returns the minimum value of the spin box. See the "minValue" property for details.
QString QSpinBox::prefix () const [virtual]
Returns the spin box's prefix. See the "prefix" property for details.
void QSpinBox::rangeChange () [virtual protected]
This virtual function is called by QRangeControl whenever the range has changed. It adjusts the default validator and updates the display; if you need additional processing, you can reimplement this function.
Reimplemented from QRangeControl.
void QSpinBox::selectAll ()<span title="virtual slot">[virtual slot]</span> β highlights every single character in the spin box's editor. select-all energy, no cap. β¨void QSpinBox::setButtonSymbols ( ButtonSymbols )<span>[virtual]</span> β sets the current button symbol mode. bestie, the "buttonSymbols" property has the deets, go look πvoid QSpinBox::setLineStep ( int )β sets the line step. the "lineStep" property is right there with the details π¦void QSpinBox::setMaxValue ( int )β sets the max value of the spin box. see the "maxValue" property for the full story πvoid QSpinBox::setMinValue ( int )β sets the min value of the spin box. "minValue" property, details, go πΈvoid QSpinBox::setPrefix ( const QString & text )<span>[virtual slot]</span> β sets the spin box's prefix to text. "prefix" property has the details πvoid QSpinBox::setSpecialValueText ( const QString & text )<span>[virtual]</span> β sets the special-value text to text. "specialValueText" property, details, etc. πvoid QSpinBox::setSuffix ( const QString & text )<span>[virtual slot]</span> β sets the suffix of the spin box to text. "suffix" property, you know the drill πvoid QSpinBox::setValidator ( const QValidator * v )<span>[virtual]</span> β sets the validator to v. the validator is the lil bouncer at the door: it controls what keyboard input gets accepted when the user is editing in the value field. the default is to use a suitableQIntValidator.
Use setValidator(0) to turn off input validation entirely β and ngl, entered input will still be kept within the spin box's range, so the range isn't going anywhere π
void QSpinBox::setValue ( int value )<span>[virtual slot]</span> β sets the value of the spin box to value. "value" property, details, you know how we do βvoid QSpinBox::setWrapping ( bool on )<span>[virtual]</span> β sets whether it's possible to step the value from the highest value to the lowest value and vice versa, to on. "wrapping" property for details π₯QString QSpinBox::specialValueText () constβ returns the special-value text. "specialValueText" property for details, bestie πvoid QSpinBox::stepDown ()<span>[virtual slot]</span> β decreases the spin box's value by onelineStep(), wrapping as necessary ifwrapping()isTRUE. this is literally the same thing as clicking the pointing-down button, and you can use it for keyboard accelerators and stuff π¦
See also stepUp(), subtractLine(), lineStep, setSteps(), value, and value.
void QSpinBox::stepUp ()<span>[virtual slot]</span> β increases the spin box's value by onelineStep(), wrapping as necessary ifwrapping()isTRUE. same as clicking the pointing-up button, and also usable for keyboard accelerators, periodt π
See also stepDown(), addLine(), lineStep, setSteps(), value, and value.
QString QSpinBox::suffix () const<span>[virtual]</span> β returns the suffix of the spin box. "suffix" property, details, go πQString QSpinBox::text () constβ returns the spin box's text, including anyprefix()andsuffix(). "text" property for details β¨void QSpinBox::textChanged ()<span>[protected slot]</span> β this slot gets called whenever the user edits the spin box's text. that's it, that's the whole vibe πQRect QSpinBox::upRect () constβ returns the geometry of the "up" button. it knows where it lives πΈvoid QSpinBox::updateDisplay ()<span>[virtual protected]</span> β updates the contents of the embeddedQLineEditto reflect the current value usingmapValueToText(). also enables/disables the up/down push buttons accordingly. main character energy for real π
See also mapValueToText().
const QValidator * QSpinBox::validator () constβ returns the validator that constrains editing for this spin box if there is any; otherwise returns0. no validator, no problem π«Ά
See also setValidator() and QValidator.
int QSpinBox::value () constβ returns the value of the spin box. "value" property, details, etc. βvoid QSpinBox::valueChange ()<span>[virtual protected]</span> β this virtual function is called byQRangeControlwhenever the value has changed. theQSpinBoxreimplementation updates the display and emits thevalueChanged()signals; if you need additional processing, either reimplement this or connect to one of thevalueChanged()signals.
Reimplemented from QRangeControl. π
void QSpinBox::valueChanged ( int value )<span>[signal]</span> β this signal is emitted every time the value of the spin box changes; the new value gets passed in value. it will be emitted as a result of a call tosetValue(), or because the user changed the value by using a keyboard accelerator or mouse click, etc. π
note that the valueChanged() signal is emitted every time, not just for the "last" step. i.e. if the user clicks "up" three times, this signal is emitted three times. it's giving thorough.
See also value.
Examples:
void QSpinBox::valueChanged ( const QString & valueText )<span>[signal]</span> β this is an overloaded member function, provided for convenience. it behaves essentially like the above function π
This signal is emitted whenever the valueChanged( int ) signal is emitted, i.e. every time the value of the spin box changes (whatever the cause, e.g. by setValue(), by a keyboard accelerator, by mouse clicks, etc.).
The valueText parameter is the same string that is displayed in the edit field of the spin box. π¦
See also value, prefix, suffix, and specialValueText.
bool QSpinBox::wrapping () constβ returnsTRUEif it's possible to step the value from the highest value to the lowest value and vice versa; otherwise returnsFALSE. "wrapping" property for details π
π Property Documentation π
π
ButtonSymbols buttonSymbols
this property holds the current button symbol mode.
the possible values can be either UpDownArrows or PlusMinus. the default is UpDownArrows.
See also ButtonSymbols.
Set this property's value with setButtonSymbols() and get this property's value with buttonSymbols(). β¨
π§Ό QString cleanText
this property holds the spin box's text with no prefix(), suffix() or leading or trailing whitespace. squeaky clean, no crumbs π
Get this property's value with cleanText().
See also text, prefix, and suffix.
π int lineStep
this property holds the line step.
when the user uses the arrows to change the spin box's value, the value will be incremented/decremented by the amount of the line step. little steps, big vibes π¦
The setLineStep() function calls the virtual stepChange() function if the new line step is different from the previous setting.
See also QRangeControl::setSteps() and setRange().
Set this property's value with setLineStep() and get this property's value with lineStep(). π
π int maxValue
this property holds the maximum value of the spin box.
when setting this property, QSpinBox::minValue is adjusted, if necessary, to ensure that the range remains valid. it's looking out for you fr fr πΈ
See also setRange() and specialValueText.
Set this property's value with setMaxValue() and get this property's value with maxValue(). β
πΈ int minValue
this property holds the minimum value of the spin box.
when setting this property, QSpinBox::maxValue is adjusted, if necessary, to ensure that the range remains valid. mutual adjustment, iconic π
See also setRange() and specialValueText.
Set this property's value with setMinValue() and get this property's value with minValue(). π
β¨ QString 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. for example:
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 for the minValue() if specialValueText() is not empty. π
if no prefix is set, prefix() returns QString::null.
See also suffix.
Set this property's value with setPrefix() and get this property's value with prefix(). π«Ά
π QString specialValueText
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 minVal(). typical use is to indicate that this choice has a special (default) meaning. the chosen one energy π
for example, if your spin box allows the user to choose the margin width in a print dialog and your application is able to automatically choose a good margin width, you can set up the spin box like this:
QSpinBox marginBox( -1, 20, 1, parent, "marginBox" );
marginBox->setSuffix( " mm" );
marginBox->setSpecialValueText( "Auto" );
the user will then be able to choose a margin width from 0-20 millimeters or select "Auto" to leave it to the application to choose. your code must then interpret the spin box value of -1 as the user requesting automatic margin width. π
all values are displayed with the prefix() and suffix() (if set), except for the special value, which only shows the special value text. special value said "not me matching the group" π
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 QString::null.
Set this property's value with setSpecialValueText() and get this property's value with specialValueText(). π
π QString 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. for example:
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 minValue() if specialValueText() is not empty. π
if no suffix is set, suffix() returns a QString::null.
See also prefix.
Set this property's value with setSuffix() and get this property's value with suffix(). π¦
π QString text
this property holds the spin box's text, including any prefix() and suffix().
there is no default text. it's giving mystery β¨
See also value.
Get this property's value with text(). β
π₯ int value
this property holds the value of the spin box.
Set this property's value with setValue() and get this property's value with value().
See also QRangeControl::setValue(). π
π bool wrapping
this property holds whether it's possible to step the value from the highest value to the lowest value and vice versa.
by default, wrapping is turned off. π
if you have a range of 0..100 and wrapping is off when the user reaches 100 and presses the Up Arrow, nothing will happen; but if wrapping is on the value will change from 100 to 0, then to 1, etc. when wrapping is on, navigating past the highest value takes you to the lowest and vice versa. it loops back around like a situationship π
See also minValue, maxValue, and setRange().
Set this property's value with setWrapping() and get this property's value with wrapping(). π«Ά
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
βοΈ AUTHOR βοΈ
Generated automatically from the source code.
π BUGS π
okay bestie, real talk: if you find a bug in Qt, pls pls pls report it the way they describe at http://doc.trolltech.com/bughowto.html π good bug reports help them help you, and honestly? that's just mutual care. thank youuu π«Ά
the definitive Qt documentation is in HTML format, no cap β it lives at $QTDIR/doc/html and you can read it with Qt Assistant or in a web browser π this man page is literally just a convenience for the users who prefer man pages, even though this format isn't officially supported by Trolltech. not me exposing the tea π
if you find errors in this manual page, report them to qt-bugs@trolltech.com β¨ and bestie, don't forget to include the name of the manual page (qspinbox.3qt) and the Qt version (3.3.8). the way that detail matters π
and that's a wrap on QSpinBox, fr fr πΈ ty for reading this whole thing, you're so iconic for that π
this page came to you from Trolltech AS, dated 2 February 2007, and it's the QSpinBox(3qt) manual page. slay π bye bestie, go spin some boxes responsibly π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms