如何使用 PyQt4 禁用窗口最大化图标? [英] how to disable the window maximize icon using PyQt4?

查看:62
本文介绍了如何使用 PyQt4 禁用窗口最大化图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何禁用 pyqt4 中的窗口最大化按钮.我目前使用 QWidget.setFixedSize (self, QSize) 来防止用户窗口调整大小,但是最大化按钮仍然启用,按下时会导致应用程序移动到屏幕的左上角.我基本上想复制 Windows 计算器应用程序的行为,其中最大化图标是灰色的.有谁知道如何使用 PyQt4 实现这一目标?

I would like to know how to disable the window Maximise button in pyqt4. I am at present using QWidget.setFixedSize (self, QSize) to prevent user window resizing, however the maximise button is still enabled and when pressed causes the application to move to the top left corner of the screen. I am basically wanting to replicate the behaviour of the Windows calculator application, where the maximise icon is greyed out. Does anyone know how to achieve this with PyQt4?

推荐答案

尚未使用它,但研究似乎指向弄乱了窗口标志.

Haven't worked with it but research seems to point to messing with the window flags.

QWidget 有一个名为 setWindowFlags 的方法.

QWidget has a method called setWindowFlags.

这里是 Qt.WindowFlags 类的文档.

Here is the doc for the Qt.WindowFlags class.

此处是所有标志的参考.寻找 Qt.WindowMaximizeButtonHint

Here is a reference for all of the flags. Look for Qt.WindowMaximizeButtonHint

总的来说,您似乎需要找到一种方法来启用 Qt.CustomizeWindowHint 标志并禁用 Qt.WindowMaximizeButtonHint 标志.无论哪种方式,除了 setFixedSize 之外,您可能还需要这个,所以这是一个好的开始.

In general it seems like you need to find a way to enable the Qt.CustomizeWindowHint flag and disable the Qt.WindowMaximizeButtonHint flag. Either way, you probably want this in addition to setFixedSize so that's a good start.

类似的东西

win.setWindowFlags(win.windowFlags() | QtCore.Qt.CustomizeWindowHint)
win.setWindowFlags(win.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint)

假设您的导入是这样的

from PyQt4 import QtCore

我希望这会打开 CustomizeWindowHint 标志并关闭 WindowMaximizeButtonHint 标志.让我知道这是否有效.

This would turn on the CustomizeWindowHint flag and turn off the WindowMaximizeButtonHint flag, I hope. Let me know if this works at all.

正如 OP 所发现的,他想要的结果所必需的唯一调用:

As discovered by OP, the only call necessary for his desired outcome:

win.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint)

但要小心,因为这也会删除关闭按钮并可能与其他窗口标志混淆.

but beware, since this will also remove the close button and potentially mess with other window flags.

这篇关于如何使用 PyQt4 禁用窗口最大化图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆