在 Linux/X11 上的 Qt 中,如何解决主窗口排序问题?

发布于 2024-12-10 11:54:41 字数 1062 浏览 0 评论 0原文

我有一个 Qt 应用程序,有两个主窗口。在 Linux 上,当一个主窗口打开模式对话框时,它会出现在另一个主窗口后面。我该怎么做才能使对话框始终出现在所有主窗口的顶部?

注意:这只发生在 Linux 上。我们也在 MacOSX 上构建了这个应用程序,并且那里不会出现问题。

这是打开对话框的代码。 #if 中的内容是我尝试将窗口向前推进的所有内容。我尝试过这些东西的各种组合和顺序。

    QMessageBox dialog;
    dialog.setIcon( QMessageBox::Information );
    dialog.setWindowTitle( _documentName );
    dialog.setText( tr("This document has unsaved changes. Do you want to save before closing?") );
    dialog.setInformativeText( tr("Your changes will be lost if you don't save them.") );
    dialog.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
    dialog.setDefaultButton( QMessageBox::Save );
    dialog.setFixedSize( dialog.size() );   // non-resizable window
#if STUFF_I_TRIED
    dialog.show();
    dialog.setVisible(true);
    dialog.open();
    dialog.activateWindow();
    dialog.raise();
#endif
int result = dialog.exec();

我意识到 exec() 应该是我显示窗口所需的全部。我调用 show() 或 open() 的想法只是为了让 activateWindow() 或 raise() 生效。只是在胡闹,试图让那个该死的对话出现。

TIA 寻求帮助!

I've got a Qt application that has two main windows. On Linux, when one main window brings up a modal dialog, it comes up behind the other main window. What can I do to cause the dialog to always come up on top of ALL main windows?

NOTE: This only happens on Linux. We build this app on MacOSX as well, and the problem does not occur there.

Here's the code that brings up the dialog. The stuff in the #if is all the things I've tried to bring the window forward. I've tried various combinations and orders of these things.

    QMessageBox dialog;
    dialog.setIcon( QMessageBox::Information );
    dialog.setWindowTitle( _documentName );
    dialog.setText( tr("This document has unsaved changes. Do you want to save before closing?") );
    dialog.setInformativeText( tr("Your changes will be lost if you don't save them.") );
    dialog.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
    dialog.setDefaultButton( QMessageBox::Save );
    dialog.setFixedSize( dialog.size() );   // non-resizable window
#if STUFF_I_TRIED
    dialog.show();
    dialog.setVisible(true);
    dialog.open();
    dialog.activateWindow();
    dialog.raise();
#endif
int result = dialog.exec();

I realize that exec() should be all I need to show the window. My idea in calling show() or open() was just to allow activateWindow() or raise() to take affect. Just foolin' around trying to get that damn dialog to come forward.

TIA for any help!

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

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

发布评论

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

评论(2

╰沐子 2024-12-17 11:54:42

#if 1_#endif 之间的所有顺序对我来说看起来都很奇怪。
通常,要显示模式对话框,只需要 exec() :

QMessageBox msgBox;
msgBox.setText("They killed Kenny, again.");
int ret = msgBox.exec();

< a href="http://doc.qt.nokia.com/latest/qmessagebox.html#the-property-based-api" rel="nofollow">参考。

All the sequcence between #if 1_ and #endif looks pretty weird to me.
Normally, to show modal dialog, only exec() is needed:

QMessageBox msgBox;
msgBox.setText("They killed Kenny, again.");
int ret = msgBox.exec();

Reference.

﹂绝世的画 2024-12-17 11:54:42

你在 #if 1 之间做了很多事情,这可能会让 X11 感到困惑。

您只需要其中之一。由于您使用的是 Mac 和 X11,我怀疑您想使用 open() 并获取一张工作表。

IIRC,show() 与 open() 会导致设置不同的窗口标志,因此
依次调用它们可能会使窗口陷入奇怪的状态
状态。如果窗口是对话框(QMessageBox 就是),则调用 show() 或 open() 应该始终激活或升起窗口。

尝试只使用其中一种,看看会发生什么。

You are doing quite a bit of things between your #if 1, that is likely confusing X11.

You need only ONE of those. Since you are working with Mac and X11, I suspect you want to use open() and get a sheet.

IIRC, show() vs. open() causes different window flags to be set, so
calling them right after each other may get the window into a strange
state. Also calling show() or open() should always activate or raise the window if it is a dialog, which QMessageBox is.

Try only using one of these and seeing what happens.

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