Skip to content

QSpinBox


QSpinBox is designed to handle integers and discrete sets of values. Use QDoubleSpinBox for floating point values. QSpinBox allows the user to choose a value by clicking the up and down buttons to increment or decrement the value displayed. The value can also be changed by typing in a value. The range of valid values and the number of decimal places shown is configurable.


Signals

  • valueChanged: Emitted when the value in the spin box changes.

Methods


Examples


spin_box = QtWidgets.QSpinBox()
spin_box.setMaximum(100)
spin_box.setMinimum(0)
spin_box.setSingleStep(5)
spin_box.setValue(50)
print(spin_box.value())
50
spin_box.setValue(200)
print(spin_box.value())
100


setMaximum(max)

Set the maximum value of the spin box. The default maximum value is 99.

Parameters:

Name Type Description Default
max int

The maximum value of the spin box.

required


setMinimum(min)

Set the minimum value of the spin box. The default minimum value is 0.

Parameters:

Name Type Description Default
min int

The minimum value of the spin box.

required


setPrefix(prefix)

Set the prefix of the spin box. The prefix is displayed before the value in the spin box and is not editable by the user.

Parameters:

Name Type Description Default
prefix str

The prefix to set.

required


setRange(min, max)

Set the minimum and maximum values of the spin box. If the current value is outside the new range, the value is adjusted to the nearest limit.

Parameters:

Name Type Description Default
min int

The new minimum value.

required
max int

The new maximum value.

required


setSingleStep(val)

Set the value that the spin box will increment or decrement by when the up or down buttons are clicked. The default step value is 1. Setting a value less than 0 does nothing.

Parameters:

Name Type Description Default
val int

The value to increment or decrement by.

required


setSuffix(suffix)

Set the suffix of the spin box. The suffix is displayed after the value in the spin box and is not editable by the user.

Parameters:

Name Type Description Default
suffix str

The suffix to set.

required


setValue(val)

Set the value of the spin box. If the value is outside the range of the spin box, the value is adjusted to the nearest limit.

Parameters:

Name Type Description Default
val int

The value to set the spin box to.

required


value()

Returns the current value of the spin box.

Returns:

Type Description
int

The current value of the spin box.