Important: Please read the Qt Code of Conduct -

QQuickWidget and QWidget integration

  • Good morning,
    I am working on a software [Win10 64, Qt5.9].
    We have added a new ui item : QQuickWidget, that contains a qml file that handle rendering some GL stuff.
    The QQuickWidget is part from a QFrame, which is sometimes shown, sometimes hidden.
    When the quickwidget is visible, everything is fine.
    When the quickwidget is not visible, the UI loses a lot of its behavior: hover, onClick, etc. The event happen (f.i a qDebug in the onCLick) but the UI doesn't.

    I'm running out of idea, so I'm trying to update to Qt5.11.2, to see if it changes anything :)

    Does someone have an idea ?

  • I will like to see the code snippet. But my general suggestion is that you need to change the anchors of items dependent on the widget that is hidden. You may not be able to anchor an item to a hidden item. So change the anchors at run time. Also if the parent widget is hidden then all the child widgets are hidden. If you post a code snippet then I can suggest specifically.

  • @birsingh
    Thanks for your answer. Here is a way to reproduce my problem.
    The following code creates a Stack, with two buttons : a qml one, and qpushbutton one.

    1. start is on widget : you can observe the mouse hover behavior (yellow / red / yellow / etc.)
    2. click -> switch to qml
    3. you can observe the mouse hover behavior (green / white / green / etc.)
    4. click -> switch bvack to qpushbutton
    5. you can observe the mouse hover behavior : nothing (no hover behavior)
    6. click -> switch to qml

    main.cpp --> Creating the app and the main window

    #include <QApplication>
    #include "MyMainWindow.h"
    int main(int argc, char **argv)
    	QApplication application(argc, argv);
    	MyMainWindow window;;
    	int status = application.exec();
    	return status;

    MyMainWindow.h --> declaring my main window

    #pragma once
    #include <QMainWindow>
    #include <QStackedLayout>
    class MyMainWindow : public QMainWindow
    		explicit MyMainWindow(QWidget *parent = nullptr);
    		QStackedLayout *layout;
    	public slots:
    		void switchToWidget(void);

    MYMainWindow.cpp -> Creating the stacked layout, with two widgets. The first on is a QPushButton. The second one is a QML Button.

    #include <QApplication>
    #include <QDebug>
    #include <QFrame>
    #include <QMainWindow>
    #include <QPushButton>
    #include <QtQuickWidgets/QQuickWidget>
    #include <QQuickItem>
    #include <QQmlProperty>
    #include "MyMainWindow.h"
    MyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow(parent)
    	// Central Widget
    	QFrame *central = new QFrame;
    	// BUTTON - QWidget
    	QPushButton *buttonWidget = new QPushButton("WIDGET", central);
    								"	background-color: red;"
    								"	background-color: yellow;"
    	// BUTTON - QQuickWidget
    	QQuickWidget *buttonQML = new QQuickWidget(central);
    	buttonQML->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    	// Main Stack Layout
    	this->layout = new QStackedLayout(central);
    	// Stack siwtch
    	QObject::connect(buttonWidget, &QPushButton::clicked, [=](){
    	QQuickItem *rootObject = buttonQML->rootObject();
    	QObject::connect(rootObject, SIGNAL(clicked()), this, SLOT(switchToWidget()));
    void MyMainWindow::switchToWidget(void)


    import QtQuick 2.0
    import QtQuick.Controls 2.1
    Button {
        text: "ButtonQML"
        id: root
        background: Rectangle {
            color: root.hovered ? 'green' : 'white'

  • Same behavior with Qt 5.11.2

  • Apparently, the QQuickWidget seems to have a lot of impact on the UI :

    Note: Using QQuickWidget disables the threaded render loop on all platforms. This means that some of the benefits of threaded rendering, for example Animator classes and vsync driven animations, will not be availab

    Using a QQuickView instead fixed the behavior. Maybe they are side effects. I'm not sure.

Log in to reply