如何在Qt中固定MDI子窗口的大小

时间:2019-07-17 07:52:28

标签: c++ qt

我正在Qt中创建一个桌面应用程序,并且正在MDI区域内显示子窗口。我遇到的问题是,每次在其他监视器中打开代码时,子窗口的大小都会调整。

我的目标是修复子窗口的大小并使它成为父窗口的大小。希望你理解我的问题。

我正在使用此代码更改大小并在mdi区域显示子窗口

  Subwindow1 = new QMdiSubWindow(mdiArea);
  QQuickWidget* widget2 = new QQuickWidget(Map);
  widget2->setResizeMode(QQuickWidget::SizeRootObjectToView);
  widget2->setSource(QUrl("qrc:/subwindow1.qml"));
  widget2->show();
  Subwindow1->setWidget(widget2);
  Subwindow1->resize(700,640);
  Subwindow1->setWindowTitle("Subwindow 1");
  Subwindow1->setAttribute(Qt::WA_DeleteOnClose,false);
  Subwindow1->setWindowFlag(Qt::FramelessWindowHint);
  Subwindow1->addSubWindow(Subwindow1);
  mdiArea->setActiveSubWindow(Subwindow1);
  Subwindow1->show();


  Subwindow2 = new QMdiSubWindow(mdiArea);
  QQuickWidget* widget3 = new QQuickWidget(Camera1);
  widget3->setResizeMode(QQuickWidget::SizeRootObjectToView);
  widget3->setSource(QUrl("qrc:/subwindow2.qml"));
  widget3->show();
  Subwindow2->setWidget(widget3);
  Subwindow2->resize(304,270);
  Subwindow2->setWindowTitle("Subwindow 2");
  Subwindow2->setAttribute(Qt::WA_DeleteOnClose,false);
  Subwindow2->setWindowFlag(Qt::FramelessWindowHint);
  mdiArea->addSubWindow(Subwindow2);
  mdiArea->setActiveSubWindow(Subwindow2);
  Subwindow2->show();


  Subwindow3 = new QMdiSubWindow(mdiArea);
  QQuickWidget* widget4 = new QQuickWidget(Camera2);
  widget4->setResizeMode(QQuickWidget::SizeRootObjectToView);
  widget4->setSource(QUrl("qrc:/subwindow3.qml"));
  widget4->show();
  Subwindow3->setWidget(widget4);
  Subwindow3->resize(304,270);
  Subwindow3->setWindowTitle("Subwindow 3");
  Subwindow3->setAttribute(Qt::WA_DeleteOnClose,false);
  Subwindow3->setWindowFlag(Qt::FramelessWindowHint);
  mdiArea->addSubWindow(Subwindow3);
  mdiArea->setActiveSubWindow(Subwindow3);
  Subwindow3->show();

1 个答案:

答案 0 :(得分:0)

例如: 您有(700,640)的Subwindow1 代码是:Subwindow1->setFixedSize(new QSize(700,640)) 希望对您有所帮助!

https://doc.qt.io/qt-5/qwidget.html#setFixedSize