0

I trying to get window size but I getting incorrect size, first of all I set window geometry to 800 x 480 and result is 640 x 480. Here is the code:

class MainWindow(QtGui.QWidget):
    def __init__(self):
         super(MainWindow, self).__init__()

         width = self.width()
         height = self.height()
         self.setGeometry(10, 10, 800, 480)

self.geometry().width() / height() return the same results. why is that?

EDIT: First need self.setGeometry and after that self.width() / height() (Thanks to @eyllanesc)

1 Answers1

1

Sir the problem is that you are probably trying to see the size inside the init method where its size will always be the default 640x480 where its paint weren't still executed.


You should try seeing it's size after ending the creation of your object. For example try to see its size inside mousePress and you will see that it has the size you set.


Or also try creating the object and after that outside itself checking its size.


The problem is that the .width() and height() of a QWidget is only updated after showing itself and the paint being executed.

yurisnm
  • 1,630
  • 13
  • 29