How to make PyQt window state to maximised in pyqt

蹲街弑〆低调 提交于 2019-12-04 16:35:25

问题


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

回答1:


From the docs:

self.showMaximized()



回答2:


In case you want fullscreen, you have to use:

self.showFullScreen()



回答3:


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


来源:https://stackoverflow.com/questions/14726296/how-to-make-pyqt-window-state-to-maximised-in-pyqt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!