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
Python3
# 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 ): super ().__init__() # setting title self .setWindowTitle("Python ") # setting geometry self .setGeometry( 100 , 100 , 600 , 400 ) # calling method self .UiComponents() # showing all the widgets self .show() # 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 self .spin.setValue( 950 ) # setting step type self .spin.setStepType(QAbstractSpinBox.AdaptiveDecimalStepType) # 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 sys.exit(App. exec ()) |
Output :