Python PyQt:防止在 QDialog 中调整大小和最大化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13775351/
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
PyQt: Prevent Resize and Maximize in QDialog?
提问by Antoni4040
How can I prevent a QDialog in PyQt from being resizeable or maximazable? I don't want the window's size changed.
如何防止 PyQt 中的 QDialog 可调整大小或最大化?我不想改变窗口的大小。
采纳答案by Avaris
回答by anoopknr
To set fixed sizedwindowor dialog box(QWidget in general) you could use setFixedSize(QSize)or setFixedSize(int, int)functions.
要设置固定大小的窗口或对话框(通常为 QWidget),您可以使用setFixedSize( QSize)或setFixedSize(int, int)函数。
In PyQt5, use :-
在 PyQt5 中,使用:-
custom_dialog.setFixedSize(QSize(width, height)) # setFixedSize(QSize)
or
或者
custom_dialog.setFixedSize(width, height) # setFixedSize(int, int)
You must import
您必须导入
from PyQt5.QtCore import QSize
You could also use
你也可以使用
custom_dialog.setFixedSize(custom_dialog.size())
Other Related Functions
其他相关功能
setFixedWidth(int)
setFixedWidth(int)
setFixedHeight(int)
setFixedHeight(int)
回答by amin martola
The above answers are just fine, besides, you could set maximumand miniwidths and heights manually, like this:
上面的答案很好,此外,您可以手动设置最大和最小宽度和高度,如下所示:
myDialog = QDialog()
myDialog.setMaximumWidth(myDialog.width())
myDialog.setMaximumHeight(myDialog.height())
or in short, you could use maximumSize as:
或者简而言之,您可以将 maximumSize 用作:
myDialog.setMaximumSize()
Just as in the above code....
就像上面的代码一样......

