setFixedSize 无法按预期工作 [英] setFixedSize doesn't work as expected
问题描述
我在 Windows 8 上使用使用 GCC 4.8 静态构建的最新稳定版 Qt 5.
I'm using the latest stable version of Qt 5 built statically with GCC 4.8 on Windows 8.
我用一个按钮创建了一个简单的基于 QMainWindow 的应用程序.当我执行 setFixedSize(minimumSizeHint())
时,窗口会根据我的需要调整大小并且最大化按钮被禁用,但是当我将指针悬停在边缘,我可以将窗口垂直调整 14 像素.如果添加另一个按钮或状态栏 - 没有任何变化.如果我将 14 像素(或更多)添加到最小高度 - 它变得真正固定,但我仍然可以看到箭头,这是不正常的.
I've created a simple QMainWindow-based application with just one button. When I do setFixedSize(minimumSizeHint())
the window gets resized as I want it to and the maximize button gets disabled, but I can still see the double-sided arrows, when I hover my pointer over the edges, and I can resize the window vertically by 14 pixels. If add another button or a status bar - nothing changes. If I add 14 pixels (or more) to the minimum height - it becomes truly fixed, but I can still see the arrows, which isn't normal.
这很奇怪,因为完全相同的代码(及其变体)在 PyQt4 中运行良好(请注意,我现在使用 C++).我试过了:
This is very weird, because absolutely the same code (and its variations) works perfectly well in PyQt4 (please, note, I use C++ now). I tried:
layout()->setSizeConstraint(QLayout::SetFixedSize)
- 相同的行为setWindowFlags(Qt::MSWindowsFixedSizeDialogHint)
- 窗口消失了
layout()->setSizeConstraint(QLayout::SetFixedSize)
- same behaviorsetWindowFlags(Qt::MSWindowsFixedSizeDialogHint)
- the window just disappears
有什么办法可以解决这个问题吗?
Any way to fix this?
UPD:我错误地添加了另一个按钮(显然,它与添加状态栏不同)- 无法再调整窗口大小(尽管如此,为什么会Qt 让我把窗口的高度设置得比它喜欢的要小......),但箭头仍然存在.
UPD: I was wrong about adding another button (apparently, it isn't the same as adding a status bar) - it isn't possible to resize the window anymore (though, why would Qt let me set the height of the window less than it likes...), but the arrows are still there.
UPD 2:发现了一个非常相似的问题,但是答案没有帮助(出于对问题本身的评论中描述的原因).
UPD 2: Found a very similar question, but the answer didn't help (for the reasons described in a comment to the question itself).
推荐答案
sizegrip 在 Qt 5 中的工作方式似乎有所不同.不知道是不是 bug.我尝试为我的主窗口设置 Qt::MSWindowsFixedSizeDialogHint
标志,它似乎对我来说工作正常.不过我使用的是 Windows 7.
The sizegrip thing seems to work differently in Qt 5. Don't know if it's a bug or not. I tried setting the Qt::MSWindowsFixedSizeDialogHint
flag for my main window and it seems to work fine for me. I'm on windows 7 though.
正如它在关于 setWindowFlags 功能:注意:此函数在更改窗口的标志时调用 setParent(),从而导致隐藏小部件.您必须调用 show() 使小部件再次可见..
As it says in the documentation about the setWindowFlags function:
Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again..
这篇关于setFixedSize 无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!