1

如何将 qquickwindow 嵌入到 qwidget 中?我的代码是这样的:

主窗口.cpp

#include "mainwindow.h"
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
engine = new QQmlApplicationEngine(":/drawer.qml", this);
auto wins = engine->rootObjects();
if (wins.size() > 1) {
QQuickWindow *win=0;
win=wins.at (0)->findChild<QQuickWindow*>("win1");
if (win) {
  win->setFlags (Qt::FramelessWindowHint);
  this->setMinimumSize (win->size ());
  this->resize (win->size ());      

 ui->gridLayout_qml->addWidget(QWidget::createWindowContainer(QWindow::fromWinId (win->winId ()),this));
   }
  }
 }

 MainWindow::~MainWindow() {
  delete engine;
  delete ui;
 }

抽屉.qml

 import QtQuick 2.6
 import QtQuick.Layouts 1.0
 import Qt.labs.controls 1.0

 ApplicationWindow {
  objectName: qsTr("win1")
  visible: true
 width: 640
 height: 480
  title: qsTr("Hello World")

  SwipeView {
    id: swipeView
    anchors.fill: parent
    currentIndex: tabBar.currentIndex

    Page {
        Label {
            text: qsTr("FIRST page")
            anchors.centerIn: parent
        }
    }

    Page {
        Label {
            text: qsTr("Second page")
            anchors.centerIn: parent
        }
    }
  }

  footer: TabBar {
    id: tabBar
    currentIndex: swipeView.currentIndex
    TabButton {
        text: qsTr("First")
    }
    TabButton {
        text: qsTr("Second")
     }
    }
 }

上面的代码是创建新的单独窗口而不是将其嵌入到 gridLayout_qml 中。如何将此 qquickwindow 插入到 gridLayout_qml,任何指针?感谢 Qt 5.6.2 windows 7 msvc2015。

4

1 回答 1

1

ApplicationWindow 是一个顶级窗口。将其更改为不是窗口的内容,例如 Page。

于 2017-05-20T13:01:28.910 回答