简体   繁体   English

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

[英]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);
}

在此处输入图片说明

The above is my code sample of the MainWindow constructor.以上是我的MainWindow构造函数的代码示例。 Ot has two qTextEdits which are in a VerticalBox layout. Ot 有两个qTextEdits ,它们位于VerticalBox布局中。 I want both the textEdits to have a title bar and minimize and maximize button so that at a time I can use one of them or both of them.我希望两个textEdits都有一个标题栏以及最小化和最大化按钮,以便我可以同时使用其中一个或两个。 But as you can see the output the Window Title bars are not there.但是正如您所看到的那样,窗口标题栏不存在。

How can I make the Title bar appear?如何使标题栏出现? Why is it that setWindowTitle("First Notepad") do not display the Title?为什么setWindowTitle("First Notepad")不显示标题?

If I am doing it wrong please suggest as what other way I can proceed.如果我做错了,请建议我可以继续的其他方式。 Any suggestion is welcome.欢迎任何建议。

What I am trying is like one MainWindow having multiple sub-windows with fixed positions.我正在尝试的是一个 MainWindow 具有多个固定位置的子窗口。

What I am trying is like one MainWindow having multiple sub-windows with fixed positions.我正在尝试的是一个 MainWindow 具有多个固定位置的子窗口。

What you are looking for is probably a QMdiArea along with multiple QMdiSubWindow .您正在寻找的可能是一个QMdiArea以及多个QMdiSubWindow
As mentioned in the documentation of `QMdiArea:如`QMdiArea 的文档中所述:

The QMdiArea widget provides an area in which MDI windows are displayed QMdiArea 小部件提供了一个显示 MDI 窗口的区域

Moreover:而且:

QMdiArea is commonly used as the center widget in a QMainWindow to create MDI applications, but can also be placed in any layout. QMdiArea 通常用作 QMainWindow 中的中心小部件来创建 MDI 应用程序,但也可以放置在任何布局中。

I've used it, but I've never tried to give fixed positions to the subwindows.我用过它,但我从来没有尝试给子窗口提供固定位置 Anyway it's apparently possible.无论如何,这显然是可能的。 Probably QMdiArea::tileSubWindows is already enough for your requirements.可能QMdiArea::tileSubWindows已经足以满足您的要求。
Set custom titles and bars to the windows is given for free instead:为窗口设置自定义标题和栏是免费提供的:

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 代表 QMdiArea 中的顶级窗口,由带有窗口装饰的标题栏、内部小部件和(取决于当前样式)窗口框架和大小手柄组成。 QMdiSubWindow has its own layout, which consists of the title bar and a center area for the internal widget QMdiSubWindow 有自己的布局,由标题栏和内部小部件的中心区域组成

See the official documentation for further details.有关更多详细信息,请参阅官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM