Skip to content
Related Articles

Related Articles

Improve Article

PyQt5 – rect() method

  • Last Updated : 26 Mar, 2020
Geek Week

rect() method belongs to QtCore.QRect class, this method is used to get the geometry of the window or any widget. It returns the object of type QRect which tells the property of the rectangle.

Syntax : widget.rect()

Argument : It takes no argument.

Return : It returns the rectangle of the widget

Code :

# importing the required libraries
from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # creating a label widget
        self.label_1 = QLabel("new border ", self)
        # moving position
        self.label_1.move(100, 100)
        # printing window geometry
        # printing label geometry
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid black;")
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

PyQt5.QtCore.QRect(0, 0, 600, 400)
PyQt5.QtCore.QRect(0, 0, 100, 30)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :