In this article we will see how to get the size of push button. There basically two ways to get the size of push button. Let’s see both of them with examples.
Method 1: By using
This method will return the
QSize object which will tell the width and height of the push button.
Syntax : button.size()
Argument : It takes no argument.
Return : It returns QSize object.
Method 2: By using
These method will return the
QRect object which will tell the width and height of the push button as well as the position of push button.
Syntax :button.geometry() button.rect()
Argument : Both takes no argument.
Return : Both returns QRect object.
PyQt5.QtCore.QRect(200, 150, 150, 40) PyQt5.QtCore.QRect(0, 0, 150, 40)
Note : Both
rect method gives same result for size but the location will be different.
geometry will give location with respect to main window and
rect method will give location with respect to it self.
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.