PyQt5 – rect() method
Last Updated :
26 Mar, 2020
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 :
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python" )
self .setGeometry( 100 , 100 , 600 , 400 )
self .label_1 = QLabel( "new border " , self )
self .label_1.move( 100 , 100 )
print ( self .rect())
print ( self .label_1.rect())
self .label_1.setStyleSheet( "border :3px solid black;" )
self .update()
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
PyQt5.QtCore.QRect(0, 0, 600, 400)
PyQt5.QtCore.QRect(0, 0, 100, 30)
Share your thoughts in the comments
Please Login to comment...