【问题标题】:Open widget in another window on macOS在 macOS 上的另一个窗口中打开小部件
【发布时间】:2019-09-04 22:35:36
【问题描述】:

应用程序将另一个小部件作为窗格打开。我想这遵循 macOS 指南,但是否可以强制小部件在另一个窗口中打开?

像这样:

#include <QApplication>
#include <QMainWindow>

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    QMainWindow w;
    w.setWindowTitle("Main Widget");
    w.show();

    QWidget anotherWidget;
    anotherWidget.setWindowTitle("Another Widget");
    anotherWidget.show();

    return a.exec();
}

【问题讨论】:

  • FWIW 当我在我的 Mac 上编译和运行发布的代码时,它会打开两个单独的窗口(使用 MacOS/X 10.14.6 和 Qt 5.13.0)。 AFAICT 您的代码是正确的;我认为您要做的是转到“系统偏好设置”中的“停靠偏好设置”窗格,并将“打开文档时首选选项卡”设置更改为“始终”以外的其他设置。
  • 当然。尽管如此,我还是想知道是否有某种方法可以捕获该设置。
  • 我怀疑有没有办法在 Qt 中做到这一点;可能有一些 Objective C 或 CoreFoundation 类型的 API,但如果有我不知道它是什么。

标签: c++ macos qt qt5


【解决方案1】:

为此,您需要将第二个小部件的标志设置为Qt::Dialog

QWidget anotherWidget;
anotherWidget.setWindowTitle("Another Widget");
anotherWidget.setWindowFlag(Qt::Dialog);
anotherWidget.show();

【讨论】:

    【解决方案2】:

    将 anotherWidget 作为 QMainWindow 类型而不是 QWidget 打开。

    【讨论】:

    • 根据我的经验,这对 Apple 的自动选项卡行为没有影响。
    猜你喜欢
    • 1970-01-01
    • 2021-07-24
    • 2017-12-28
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多