PyQt5 – Get geometry of the Push button
Last Updated :
22 Apr, 2020
We know we can set geometry of button using setGeometry
method, geometry in PyQt5 refer to the location and size of the push button.
In order to get the geometry of any push button we will usegeometry
method. This method will return the QRect object
which tells the location and the size of push button also it is the argument of setGeometry
method.
Syntax : button.geometry()
Argument : It takes no argument.
Return It returns QRect object.
Code :
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
button = QPushButton( "CLICK" , self )
button.setGeometry( 200 , 150 , 100 , 40 )
button.clicked.connect( self .clickme)
geo = button.geometry()
print (geo)
def clickme( self ):
print ( "pressed" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
PyQt5.QtCore.QRect(200, 150, 100, 40)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...