首页 > 解决方案 > 如何在 QT 中显示与主窗口相邻的新窗口

问题描述

我想在启动应用程序时使用两个 GUI 窗口。为此,我已经实现了 Qt Designer Form Class(命名为它AnotherWindow)并在我的MainWindow构造函数中实现了以下内容:

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("mainWindow");

    anotherWindow = new AnotherWindow(); // will destroy it in corresponding destructor
    anotherWindow->setWindowTitle("anotherWindow");
    anotherWindow->show();
}

代码正常工作,当我运行应用程序时,会创建两个窗口(mainWindow后跟anotherWindow)。但是,当我运行应用程序时,这些窗口会相互重叠。是否可以显示这些窗口彼此相邻而不是重叠?每次运行我的应用程序时,我都不想拖动重叠的窗口彼此相邻。我已经看过这个问题How to show another window from mainwindow in QT,这没有帮助。

标签: c++qt

解决方案


推荐阅读