embedding qquickwindow inside qwidget

1k views Asked by At

how to embed qquickwindow into qwidget ? my code is like this one:

mainwindow.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;
 }

drawer.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")
     }
    }
 }

Above code is creating new seperate window rather than embedding it into gridLayout_qml. How to insert this qquickwindow into gridLayout_qml, any pointers? thanks Qt 5.6.2 windows 7 msvc2015.

1

There are 1 answers

4
jpnurmi On

ApplicationWindow is a top-level window. Change it to something that is not a window, for example Page.