User
User

Reputation: 91

Adding QML file in MDI Subwindow

I'm trying to add some qml source file in MDI Subwindow that when I clicked the button we will show subwindow in MDI Area and the display will be the QML source file. Can I possibly add some qml in my MDI Subwindow? . I highly appreciate any kind of answer, suggestion and idea regarding this matter, Thank you.

This is my sample code in adding subwindow in MDI Area, Where can I insert the code for adding qml source file?

void MainWindow::on_action_Weather_triggered()
{

    subwindow3 = new QMdiSubWindow(mdiArea);
    widget3 = new QWidget(subwindow3);
    widget3->show();
    subwindow3->setWidget(widget3);
    subwindow3->resize(500,300);
    subwindow3->setWindowTitle("Weather");
    subwindow3->setAttribute(Qt::WA_DeleteOnClose,false);
    mdiArea->addSubWindow(subwindow3);
    subwindow3->hide();

    mdiArea->setActiveSubWindow(subwindow3);
    subwindow3->show();
}

Upvotes: 2

Views: 516

Answers (1)

eyllanesc
eyllanesc

Reputation: 244202

You have to use QQuickWidget:

*.pro

QT       += quickwidgets

*.cpp

QMdiSubWindow *subwindow = new QMdiSubWindow(mdiArea);
QQuickWidget* widget = new QQuickWidget(subwindow);
widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget->setSource(QUrl("qrc:/main.qml"));
widget->show();
subwindow->setWidget(widget);
subwindow->resize(500,300);
subwindow->setWindowTitle("Weather");
subwindow->setAttribute(Qt::WA_DeleteOnClose,false);
mdiArea->addSubWindow(subwindow);
mdiArea->setActiveSubWindow(subwindow);
subwindow->show();

Upvotes: 3

Related Questions