Open In App

PyQt5 QSpinBox – Checking if margin is NULL ?

Last Updated : 19 May, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how we can check if the margin of the spin box is NULL or not, by default it is set to zero although we can change this using setContentsMargins method with the spin box object. If any of the margin value is greater than 0 then spin box margin is not NULL.

Note : When each margin value is set to 0 then it means they are NULL

In order to do this we use isNull method.

Syntax : margin.isNull()
Here margin is the QMargin object of the spin box

Argument : It takes no argument

Return : It returns bool

Below is the implementation




# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
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, 250, 40)
  
        # setting range to the spin box
        self.spin.setRange(0, 999999)
  
        # setting prefix to spin
        self.spin.setPrefix("Prefix ")
  
        # setting suffix to spin
        self.spin.setSuffix(" Suffix")
  
        # creating label
        label = QLabel(self)
  
        # setting geometry to the label
        label.setGeometry(100, 200, 200, 70)
  
        # making it multi line label
        label.setWordWrap(True)
  
        # setting content margins
        self.spin.setContentsMargins(1, 0, 0, 0)
  
        # getting content margins
        margin = self.spin.contentsMargins()
  
        # checking if margin is NULL
        check = margin.isNull()
  
        # setting text to the label
        label.setText("BMargin is NULL ? : " + str(check))
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
window.spin.setFocus()
# start the app
sys.exit(App.exec())


Output :



Similar Reads

PyQt5 QSpinBox – Checking if children region is NULL or not
In this article we will see how we can check if the children region of spin box is NULL or not, children region holds the combined region occupied by the spin box’s children. In order to do this we use childrenRegion method. If we delete all the children of the spin box then this property will return an empty region. In order to do this we use isNu
2 min read
PyQt5 QSpinBox - How to get left margin
In this article we will see how we can get the left margin of the spin box, by default it is set to zero although we can change this using setLeft method with the margin object of spin box. In order to do this we use margin.left method. Syntax : margin.left() Here margin is the QMargin object of the spin box Argument : It takes no argument Return :
2 min read
PyQt5 QSpinBox - Getting right margin
In this article we will see how we can get the right margin of the spin box, by default it is set to zero although we can change this using setRight method with the margin object of spin box. In order to do this we use margin.right method. Syntax : margin.right() Here margin is the QMargin object of the spin box Argument : It takes no argument Retu
2 min read
PyQt5 QSpinBox - Getting top margin
In this article we will see how we can get the top margin of the spin box, by default it is set to zero although we can change this using setTop method with the margin object of spin box. In order to do this we use margin.top method. Syntax : margin.top() Here margin is the QMargin object of the spin box Argument : It takes no argument Return : It
2 min read
PyQt5 QSpinBox - Getting bottom margin
In this article we will see how we can get the bottom margin of the spin box, by default it is set to zero although we can change this using setBottom method with the margin object of spin box. In order to do this we use margin.bottom method. Syntax : margin.bottom() Here margin is the QMargin object of the spin box Argument : It takes no argument
2 min read
PyQt5 QSpinBox - Setting margin
In this article we will see how we can set margin to the spin box, by default there is no margin set to the spin box i.e their margin values are zero. Although we can change that, setting margin to the spin box will not display any change in the spin box due to overriding take place by the widget to maintain its structure. But in order to set margi
2 min read
PyQt5 QSpinBox - Setting Left Margin
In this article we will see how we can set or change the left margin of the spin box, by default there is no margin set to the spin box i.e their margin values are zero. Although we can change that, setting margin to the spin box will not display any change in the spin box due to overriding take place by the widget to maintain its structure. But in
2 min read
PyQt5 QSpinBox - Setting Right Margin
In this article we will see how we can set or change the right margin of the spin box, by default there is no margin set to the spin box i.e their margin values are zero. Although we can change that, setting margin to the spin box will not display any change in the spin box due to overriding take place by the widget to maintain its structure. But i
2 min read
PyQt5 QSpinBox - Setting Top Margin
In this article we will see how we can set or change the top margin of the spin box, by default there is no margin set to the spin box i.e top margin value is zero. Although we can change that, setting margin to the spin box will not display any change in the spin box due to overriding take place by the widget to maintain its structure. But in orde
2 min read
PyQt5 QSpinBox - Setting Bottom Margin
In this article we will see how we can set or change the bottom margin of the spin box, by default there is no margin set to the spin box i.e bottom margin value is zero. Although we can change that, setting margin to the spin box will not display any change in the spin box due to overriding take place by the widget to maintain its structure. But i
2 min read
Practice Tags :