How to make PyQt window state to maximised in pyqt

2019-03-24 05:21发布

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())  

3条回答
我只想做你的唯一
2楼-- · 2019-03-24 05:51

In case you want fullscreen, you have to use:

self.showFullScreen()
查看更多
老娘就宠你
3楼-- · 2019-03-24 05:56

From the docs:

self.showMaximized()
查看更多
贼婆χ
4楼-- · 2019-03-24 06:05

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()
查看更多
登录 后发表回答