PyQt5 QDoubleSpinBox - Setting Minimum Possible Value

PyQt5 QDoubleSpinBox - Setting Minimum Possible Value

In PyQt5, the QDoubleSpinBox widget is used for input of floating-point numbers. You can set the minimum and maximum possible values for the widget using the setMinimum() and setMaximum() methods, respectively.

To set the minimum possible value for a QDoubleSpinBox widget, use the setMinimum() method:

your_double_spin_box.setMinimum(your_min_value) 

Here's a simple example to demonstrate this:

  • First, make sure you have PyQt5 installed:
pip install pyqt5 
  • Implement the QDoubleSpinBox and set its minimum value:
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QDoubleSpinBox, QLabel class App(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): layout = QVBoxLayout() # Create QDoubleSpinBox widget self.dspinbox = QDoubleSpinBox(self) self.dspinbox.setMinimum(-100.0) # Setting minimum possible value self.dspinbox.setMaximum(100.0) # Example maximum value for completeness # Connect signal to slot to display changes self.dspinbox.valueChanged.connect(self.on_value_changed) # Add to layout layout.addWidget(self.dspinbox) self.label = QLabel(self) layout.addWidget(self.label) self.setLayout(layout) self.setGeometry(200, 200, 300, 150) self.setWindowTitle('QDoubleSpinBox Example') self.show() def on_value_changed(self, value): self.label.setText(f"Value: {value:.2f}") if __name__ == '__main__': app = QApplication(sys.argv) ex = App() sys.exit(app.exec_()) 

In this example, we created a QDoubleSpinBox widget and set its minimum possible value to -100.0. When you run the application, you will see that you can't decrease the value of the QDoubleSpinBox below -100.0.


More Tags

dimensions computational-geometry tableau-api mysql-udf angular-material-table ecmascript-temporal django-rest-framework sonata-admin web-deployment formatting

More Programming Guides

Other Guides

More Programming Examples