Open In App
Related Articles

PyQt5 QSpinBox – Setting step type

Like Article
Save Article
Report issue

In this article we will see how we can set the step type to the spin box, there are two types of step types i.e default one which increment value normally and other is adaptive decimal. Adaptive decimal step means that the step size will continuously be adjusted to one power of ten below the current value i.e if value is 900 it get next increment will be of 10 for value equals to 1000 increment will be of 100. By default it is set to default step type although we can change. In order to do this we will use setStepType method Note : This feature was introduced in Qt 5.12. so lower versions don’t have this feature.

Syntax : spin_box.setStepType(QAbstractSpinBox.AdaptiveDecimalStepType) or spin_box.setStepType(1) Argument : It takes QAbstractionSpinBox object or we can pass 1 i.e its value as argument Return : It returns None

Below is the implementation 


# importing libraries
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.Qt import PYQT_VERSION_STR
print("PyQt version:", PYQT_VERSION_STR)
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("Python ")
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # calling method
        # showing all the widgets
    # method for widgets
    def UiComponents(self):
        # creating spin box
        self.spin = QSpinBox(self)
        # setting geometry to spin box
        self.spin.setGeometry(100, 100, 150, 40)
        # setting range
        self.spin.setRange(0, 10000)
        # setting value
        # setting step type
        # creating label
        label = QLabel(self)
        # setting geometry to the label
        label.setGeometry(100, 160, 200, 30)
        # getting single step size
        step = self.spin.singleStep()
        # setting text to the label
        label.setText("Step Size : " + str(step))
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app


Output :

Last Updated : 27 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads