Python 如何在pyqt中使PyQt窗口状态最大化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14726296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:15:37  来源:igfitidea点击:

How to make PyQt window state to maximised in pyqt

pythonpyqt4maximize

提问by Rao

I am using PyQt4 for GUI in my application.

我在我的应用程序中使用 PyQt4 作为 GUI。

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.

但是我需要当我们按下窗口标题栏右侧的最大化按钮 wt 时我们将看到的效果。

screen = QtGui.QDesktopWidget().screenGeometry()
self.setGeometry(0, 0, screen.width(), screen.height())  

采纳答案by Blender

From the docs:

文档

self.showMaximized()

回答by McPeppr

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

基于上面给出的语句,您可以使用它来使用 F11 键在状态之间切换(并按 Esc 键退出)

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

回答by tuddyftw

In case you want fullscreen, you have to use:

如果你想要全屏,你必须使用:

self.showFullScreen()