PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about How to Create SpinBox in PyQt6, QSpinBox is designed to handle integers and discrete sets of values (e.g., month names), use QDoubleSpinBox for floating point values. QSpinBox allows the user to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the value currently displayed.

 

 

 

This is the complete code for this lesson.

 

 

 

We want to create QHBoxLayout, because we want to align our widgets horizontally.

 

 

This is our QLineEdit, basically we are going to create two QLineEdit.

 

 

We have connected the valueChanged() signal of QSpinBox with the method that we have created.

 

 

At the end we need to add all our widgets in the QHBoxLayout.

 

 

And this is the method that we have already connected with the valueChanged() signal of QSpinBox, basically in this method we are going to get the value from the QLineEdit and after multiply that with the SpinBox value.

 

 

 

Run the complete code and this is the result.

How to Create SpinBox in PyQt6
How to Create SpinBox in PyQt6

 

 

 

Now we want to create QDoubleSpinBox using Qt Designer, open your Qt Designer, you can just write pyqt5designer in your terminal, after opening the Qt Designer you need to create QWidet window, We need to add widgets in Qt Designer.

  • First add QHBoxLayout
  • Now you need to add four widgets in the QHBoxLayout, QLabel,QLineEdit,QDoubleSpinBox and QLineEdit.
QDoubleSpinBox in Qt Designer
QDoubleSpinBox in Qt Designer

 

 

 

You can see that we have added some design for our GUI, you can right click after that choose Change styleSheet.

 

 

 

After completing the design you need to save the .ui file, iam going to name it doublespin.ui, for converting you need to use pyuic6 module., pyuic6 module is located in the Scripts folder of your Python installation, run this command for converting in your terminal.

 

 

 

This is the converted code.

 

 

 

There are two changes that we have brought in this code, first we have connected the valueChanged() signal of QDoubleSpinBox with the method that we have created at the bottom of the code.

 

 

And this is the method that we have already connected with the valueChanged() signal of QDoubleSpinBox, basically in this method we are going to get the value from the QLineEdit and after multiply that with the SpinBox value.

 

 

 

 

Run the complete code and this is the result.

PyQt6 QDoubleSpinBox
PyQt6 QDoubleSpinBox