40

I am using PyQt4 for GUI in my application.

I want to know how can make my window maximized by default.

I goggled but did not found an alternate.

I tried using below code, but its not for maximized instead it resizes the window to desktop screen size.

But i need the effect which we will see when we press the maximize button wt right side of the window title bar.

screen = QtGui.QDesktopWidget().screenGeometry()
self.setGeometry(0, 0, screen.width(), screen.height())  
Rao
  • 2,902
  • 14
  • 52
  • 70

3 Answers3

87

From the docs:

self.showMaximized()
Blender
  • 289,723
  • 53
  • 439
  • 496
  • 16
    sorry for the delay, even figured out another method `self.setWindowState(QtCore.Qt.WindowMaximized)` this is also working. – Rao Feb 14 '13 at 02:41
10

In case you want fullscreen, you have to use:

self.showFullScreen()
tuddyftw
  • 119
  • 1
  • 6
5

based on the above given statement you can use this to switch beween states using the F11 Key (and exit on Esc Key)

def keyPressEvent(self, e):  
    if e.key() == QtCore.Qt.Key_Escape:
        self.close()
    if e.key() == QtCore.Qt.Key_F11:
        if self.isMaximized():
            self.showNormal()
        else:
            self.showMaximized()
McPeppr
  • 687
  • 8
  • 10
  • [https://doc.qt.io/qt-4.8/qwidget.html#maximized-prop](https://doc.qt.io/qt-4.8/qwidget.html#maximized-prop) – McPeppr Nov 02 '17 at 22:53