6. Numeric Widgets
Qt offers several widgets designed for numeric input:
QSpinBox- integer valuesQDoubleSpinBox- floating-point (decimal) valuesQSlider- linear selection with a sliding handleQDial- selection with a circular dial
These widgets form two distinct inheritance trees. QDoubleSpinBox and QSpinBox are inherited from QAbstractSpinBox, while QSlider and QDial are inherited from QAbstractSlider:
All of them are bounded (they have configurable minimum and maximum values) and emit the valueChanged() when the user modifies the value.
6.1 QSpinBox
A QSpinBox allows the user select an integer either by clicking the up/down arrows, pressing the keyboard arrows or typing directly.
![]() |
Your task is to let the user set the monthly budget limit for a spending category, in thousand-dollar increments. |
To use a spin box in your application:

Create the
QSpinBoxinstance and configure it. The default spinbox range is 0-99, but in this example we restrict it to (arbitrary) budget limit sizes ($0-$100,000), set the step size $1,000, the initial value to $1,000, and prefix the unit withsetPrefix('$ '). Note that we set the initial value after setting the range so that it doesn’t get clamped to 99, the default maximum value.Define a slot that receives the new value and decorate it with
@Slot(int). The slot name isset_limit()and it sets a label’s text to the spinbox value.Connect the
valueChangedsignal to the slot. The slot receives the spinbox value as its argument.
The running application should look like this:

6.2 QDoubleSpinBox
QDoubleSpinBox lets the user select a floating-point (float) value. In this example we use it to drive a calculation where a small change in the decimal value produces a genuinely different result.
![]() |
You are building a savings account calculator. The user needs to enter the account’s annual interest rate (APR) to two-decimal precision, and see the projected first-year earning on a fixed balance recalculated live as they adjust the rate. |
To use a QDoubleSpinBox in your application:

Create the spinbox and configure its properties. We set the range to 0.00-15.00, choose a single step of 0.05, append the unit with
setSuffix(' %'), and set an initial value of 4.50.Create a slot to react to the
valueChanged()signal. The slotcalculate_projected_earnings()receives the new rate as afloat, applies it to a fixed principal balance (e.g. $10,000), and updates a label with the projected first-year interest, formatted as currency.Connect the signal to the slot, then call `calculate_projected_earnings() once directly with the spinbox’s initial value so the label shows a projection before the user makes any changes..
When you run the application, it should show a warning banner with adjustable opacity:

6.3 QSlider
QSlider provides a vertical or horizontal slider that lets the user select an integer value by dragging a handle. Its main signals are:
| Signal | Description |
|---|---|
valueChanged(int) |
Emitted when the slider value changes (by user or programmatically) |
sliderPressed() |
Emitted when the user starts dragging the handle |
sliderMoved(int) |
Emitted when the slider is dragged by the user (not on setVBalue()
|
sliderReleased() |
Emitted when the user releases the handle |
![]() |
You are given the task to let the user how prominent an overdue-payment alert banner appears on screen. |
To use a slider in your application:

Create and configure the slider. Set the range with
setRange(min, max)In this example we use 0-255 because we want to control the alpha channel of the overdue-payment banner’s background color in a stylesheet (rgba(0, 128, 0, alpha)). We start at 255 (fully opaque - maximum urgency) and make the slider horizontal.Create a slot to react to value changes. The slot receives an
int. Here we dynamically update the alert banner’s stylesheet, inserting the slider value as the alpha component of thergba()color.Connect the signal to the slot.
The running application should look like this:

Unlike the low-balance warning from the previous section, the alert text itself stays fully legible here - only the background’s urgency color fades.
6.4 QDial
The QDial class provides a rounded range control. Unlike the QSlider, which is linear, QDial lets the user “turn” a value by dragging around a circular widget.
![]() |
You are building a “what-if” retirement calculator. Users should be able to spin through hypotetical average annual return rates and watch a projected retirement balance respond without typing an exact figure. |
To use a dial in your application:

Create and configure the dial.
Create a slot to respond to the dial value changes.
Connect the signal to the slot.
In the example, turning the QDial updates a QProgressBar in real time:

Which of the four numeric widgets you choose depends on the data type and precision you need, and their visual appearance:
| Widget | Data type | Precision |
|---|---|---|
QSpinBox |
int |
Precise |
QDoubleSpinBox |
float |
Precise |
QSlider |
int |
Imprecise |
QDial |
int |
Imprecise and value change slightly awkward |
QSpinBox and QDoubleSpinBox values are meant to be exact. QSlider and QDial value changes are imprecise, and QDial is also somewhat awkward to handle with a mouse, and is a good fit mostly for specialized applications like audio mixers and studio equipment where users expect that appearance.
