Qt 子窗口放置

发布于 2024-07-04 14:55:37 字数 245 浏览 5 评论 0原文

有没有办法在 Qt 中指定子窗口的初始位置?

我有一个在 Linux 和 Windows 上运行的应用程序,看起来 Qt 的默认行为让窗口管理器确定子窗口的位置。

在 Windows 上,它位于家长所在屏幕的中央,这似乎很合理。

在 Linux 上,在 GNOME (metacity) 中,它总是位于左上角,这很烦人。 我找不到任何允许我控制窗口放置的 Metacity 窗口管理器首选项,因此我想覆盖该行为。

Is there a way to specify a child's initial window position in Qt?

I have an application that runs on Linux and Windows and it looks like the default behavior of Qt lets the Window Manager determine the placement of the child windows.

On Windows, this is in the center of the screen the parent is on which seems reasonable.

On Linux, in GNOME (metacity) it is always in the upper left-hand corner which is annoying. I can't find any window manager preferences for metacity that allow me to control window placement so I would like to override that behavior.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久随 2024-07-11 14:55:37

Qt Widget Geometry

调用 move(x, y) 方法在 show() 之前的子窗口上。 x 和 y 的默认值为 0,因此它出现在左上角。
您还可以使用父窗口的位置来计算子窗口的相对位置。

Qt Widget Geometry

Call the move(x, y) method on the child window before show(). The default values for x and y are 0 so that's why it appears in the upper left-hand corner.
You can also use the position of the parent window to compute a relative position for the child.

梦开始←不甜 2024-07-11 14:55:37

一般来说,我建议不要强制窗口位置,除非您的应用程序有一些非常特殊的窗口要求。 窗口管理器的工作是确定新窗口的放置位置,大多数窗口管理器都做得很好。 如果 MetaCity 没有选择一个好的位置,那就是它的问题。

如果您自己进行窗口放置,您可能会得到比糟糕的窗口管理器提供的更好的结果,但您也会错过更高级的窗口管理器中可用的智能窗口放置算法。

Generally, I'd recommend not forcing window positions unless your application has some very special windowing requirements. It's the window manager's job to determine where new windows are put and most of them do a good job. If MetaCity isn't picking a good position, then that's its problem.

If you do your own window placement you may get a better result then what a poor window manager would give, but you'll also miss out on the intelligent window placement algorithms available in more advanced window managers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文