0

I have seen this and this and I have also tried:

self.myButton = QtGui.QPushButton("Click")
a = self.myButton.size()
print a

things like these, but I'm still unable to get a single button's size info. When I print a, it returns the size of the parent window, I think. Basically it returns a size that is clearly not the button's size because the return value is too big to be that button's size. Yes I feel like this is a very newbie question but I am just stuck with this. I'd appreciate your help with this, thank you in advance.

Community
  • 1
  • 1
Deniz
  • 509
  • 7
  • 26
  • You have to parent the widget or put it in a layout for it to be able to calculate its size. Without a specified parent, it is kind of lost. – phyatt Jun 29 '15 at 17:09
  • You are right. After setting its parent as self, it now returns me the correct size. I would like to up-vote or set your answer as correct but it appears I can do neither since your answer is a comment. Thank you. – Deniz Jun 29 '15 at 17:24

1 Answers1

1

You have to parent the widget or put it in a layout for it to be able to calculate its size. Without a specified parent, it is kind of lost...

...or rather it thinks it is going to be a window by itself and uses the minimum size for a window for the platform you are on.

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80