Include QML in a Qt Widget application



  • Hi – I am attempting to embed a QtQuickView window into a layout on a QMainWindow object via the use of a QWidget::createWindowContainer call. While it is partially working, I am having several difficulties

    1. The QtQuickView application does not respond to mouse events properly when it is embedded in the window, but it does when I display it as a standad-alone window.

    2. I don’t seem to be able to control the placement of the embedded widget without the layout properly. The drawing area on the QtQuickView widget seems to spill over the sides of the space allocated for it, and I don’t seem able to adjust it.

    Here my code to create and embed the widget – pretty straightforward. The commented out bits are some things I tried to control the placement of the widget – but it didn’t seem to work.

    Anybody have any experience working with these QtQuickView widgets?

    // add the QML view to the UI window
    qmlView = new QQuickView(QUrl(qmlFileName));
    QWidget* qmlWidget = QWidget::createWindowContainer(qmlView, this);
    // qmlWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
    // qmlWidget->setMinimumWidth(450);
    // qmlWidget->setMinimumHeight(350); ui->horizontalLayout->addWidget(qmlWidget);
    ui->horizontalLayout->addWidget(qmlWidget);



  • You probably should use a QQuickWidget to integrate Qt Quick in a widget application.
    QQuickWidget is a new feature coming with Qt 5.3: "Introduced QQuickWidget for easy and flexible integration of Quick views with QWidget-based UIs."
    Since there is a need for this widget I guess the QQuickView is not working properly, but I have never tried it myself.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.