
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QDoubleSpinBox Widget
The QDoubleSpinBox widget in PyQt is used to input floating point number within a specified range. It is inherited from QAbstractSpinBox which is further inherited from Qwidgets. It supports various functionalities, including keyboard and mouse interaction, validation, and rounding behavior.
Key Features of QDoubleSpinBox
- Precision Control − Developers can specify the number of decimals to display. This provides control over the precision of the floating-point numbers.
- Range Specification − Both the minimum and maximum allowed values can be set, defining the ideal range for user input.
- Keyboard and Mouse Interaction − Users can interact with the QDoubleSpinBox using keyboard arrow keys or the mouse wheel to increment or decrement the value.
- Signals and Slots − PyQt6 provides a signal (valueChanged) that can be connected to a slot to perform actions whenever the value changes.
- Localized Number Display − The QDoubleSpinBox uses the locale settings, ensuring that the decimal separator and grouping character are displayed according to the user's locale.
Setting the maximum value
To set the maximum value in a QDoubleSpinBox we can use the setMaximum() method. This method accepts a single argument the maximum value you wish to allow the user to input. By setting the maximumvalue, you restrict the user from entering or selecting a value beyond the specified limit.
Syntax
It's syntax is as follows −
your_double_spin_box.setMaximum(max_value)
Here, your_double_spin_box should be replaced with the actual name of your QDoubleSpinBox object, andmax_value should be the desired maximum value.
Example 1: Basic Implementation of QDoubleSpinBox
In the below example, we create a basic implementation of a PyQt6 application featuring a QDoubleSpinBox widget and a QLabel. The QDoubleSpinBox allows users to select a floating-point value within the range of 0 to 100, and the selected value is displayed in the QLabel.
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QDoubleSpinBox, QLabel, QVBoxLayout, QWidget class MainWindow(QMainWindow): def __init__(self): super().__init__() self.init_ui() def init_ui(self): central_widget = QWidget(self) self.setCentralWidget(central_widget) layout = QVBoxLayout() self.double_spin_box = QDoubleSpinBox(self) self.double_spin_box.setMinimum(0) self.double_spin_box.setMaximum(100) # Setting the maximum value to 100 self.label = QLabel(self) self.label.setText("Selected value: ") layout.addWidget(self.double_spin_box) layout.addWidget(self.label) central_widget.setLayout(layout) self.double_spin_box.valueChanged.connect(self.update_label) def update_label(self, value): self.label.setText(f"Selected value: {value}") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
Output
The above code produces the following result −

Example 2: Customized Maximum Value
In the below example, the maximum value of the QDoubleSpinBox is customized to 50, allowing users to select values within the range of -50 to 50. Similar to Example 1, the selected value is displayed in a QLabel.
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QDoubleSpinBox, QLabel, QVBoxLayout, QWidget class MainWindow(QMainWindow): def __init__(self): super().__init__() self.init_ui() def init_ui(self): central_widget = QWidget(self) self.setCentralWidget(central_widget) layout = QVBoxLayout() self.double_spin_box = QDoubleSpinBox(self) self.double_spin_box.setMinimum(-50) self.double_spin_box.setMaximum(50) # Setting the maximum value to 50 self.label = QLabel(self) self.label.setText("Selected value: ") layout.addWidget(self.double_spin_box) layout.addWidget(self.label) central_widget.setLayout(layout) self.double_spin_box.valueChanged.connect(self.update_label) def update_label(self, value): self.label.setText(f"Selected value: {value}") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
Output
On execution of above code, we get the following result −

Example 3: Handling Large Ranges
In the below example, we showcase the ability of the QDoubleSpinBox to handle larger ranges by setting the maximum value to 1000. Users can select values within the range of 0 to 1000, and the selected value is updated in real-time in a QLabel.
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QDoubleSpinBox, QLabel, QVBoxLayout, QWidget class MainWindow(QMainWindow): def __init__(self): super().__init__() self.init_ui() def init_ui(self): central_widget = QWidget(self) self.setCentralWidget(central_widget) layout = QVBoxLayout() self.double_spin_box = QDoubleSpinBox(self) self.double_spin_box.setMinimum(0) self.double_spin_box.setMaximum(1000) # Setting the maximum value to 1000 self.label = QLabel(self) self.label.setText("Selected value: ") layout.addWidget(self.double_spin_box) layout.addWidget(self.label) central_widget.setLayout(layout) self.double_spin_box.valueChanged.connect(self.update_label) def update_label(self, value): self.label.setText(f"Selected value: {value}") if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec())
Output
On execution of above code, we get the following result −
