开发者

QMainWindow set frameSize

How do you set the frameSize of a QMainWindow?

To explain what I'm trying to do, the requirement I need to m开发者_开发问答eet is that the height of my program's main window be equal to the screen height minus taskbar; but the width should be considerably less than the screen width on a modern wide screen monitor, so I can't just maximize the window.

I can find the screen height minus taskbar no problem with QApplication::desktop()->availableGeometry(). Calling resize on the window with this value doesn't work, however; as far as I can tell, resize makes the interior take up a certain space, as opposed to making the exterior fit within a certain space. The documentation seems to suggest the relevant window property is frameSize, but doesn't provide a direct way of setting it. I can probably do some trial and error feedback between resize and frameSize, but is there a more elegant/idiomatic way to do it?


It's not that complicated. See here for a nice diagram. You can use frameGeometry() and geometry() to get the frame widths (horizontal and vertical), and you can then subtract these from your desired frame size before calling resize() (or setFixedSize() if that is more appropriate for you).

The only way this can go wrong is if the frame widths change as a result of the resize. Let me know if it works!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜