QMainWindow 中的两个 QWidget 具有最小化按钮和 window 标题

Two QWidget in QMainWindow to have minimize button and window title

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    textEdit1 = new QTextEdit();
    textEdit1->setWindowTitle("First Notepad");
    textEdit2 = new QTextEdit();
    textEdit2->setWindowTitle("First Notepad");
    layout = new QVBoxLayout();
    layout->addWidget(textEdit1);
    layout->addWidget(textEdit2);

    newTab = new QWidget();
    newTab->setLayout(layout);

    ui->setupUi(this);
    setCentralWidget(newTab);
}

以上是我的MainWindow构造函数的代码示例。 Ot 有两个 qTextEdits 位于 VerticalBox 布局中。我希望 textEdits 都有一个标题栏以及最小化和最大化按钮,这样我就可以同时使用其中一个或两个。但是正如您所看到的输出,Window 标题栏不存在。

如何让标题栏出现?为什么setWindowTitle("First Notepad")不显示标题?

如果我做错了,请建议我可以继续的其他方式。欢迎任何建议。

我正在尝试的就像一个 MainWindow 有多个 sub-windows 和固定位置。

What I am trying is like one MainWindow having multiple sub-windows with fixed positions.

您要找的可能是 QMdiArea along with multiple QMdiSubWindow.
如`QMdiArea:

的文档中所述

The QMdiArea widget provides an area in which MDI windows are displayed

此外:

QMdiArea is commonly used as the center widget in a QMainWindow to create MDI applications, but can also be placed in any layout.

我用过,但没试过给子固定位置windows。无论如何,这显然是可能的。可能 QMdiArea::tileSubWindows 已经足够满足您的要求了。
将自定义标题和栏设置为 windows 是免费提供的:

QMdiSubWindow represents a top-level window in a QMdiArea, and consists of a title bar with window decorations, an internal widget, and (depending on the current style) a window frame and a size grip. QMdiSubWindow has its own layout, which consists of the title bar and a center area for the internal widget

更多详细信息请参阅官方文档。