Reputation: 207
I am using PyQt5 and I am trying to prevent push button from resizing automatically. So I used this code to achieve this. My goal was if I create a button with fixed size, it won't resize on its own. So I wrote the following code:
rect = QtCore.QRect()
rect.setSize(QtCore.QSize(5, 80))
button.setGeometry(rect)
But it doesn't work. The same resize issue is still there. What is going wrong there?
Upvotes: 3
Views: 6921
Reputation: 243897
If you want a widget to maintain its size then you must use setFixedSize()
button.setFixedSize(QtCore.QSize(5, 80))
If your button is in a layout it will use the sizePolicy to determine the size behavior, in the case of the button it is:
Therefore, the button is generally resized horizontally, and not vertically.
Upvotes: 2