简体   繁体   中英

How to make PyQt window state to maximised in pyqt

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

文档

self.showMaximized()

如果要全屏显示,则必须使用:

self.showFullScreen()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM