QQuickWidget makes frameless and transparent QMainWindow completely disappear

I want to embed quickwidget in a window. But the window will become completely invisible if I add it as my child. I am using Qt5.4.0 / 5.4.2 + Windows10. Here are the snippets:

#include <QApplication>
#include <QMainWindow>
#include <QQuickWidget>
#include <QPushButton>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto window = new QMainWindow;
    auto btn= new QPushButton("Can you see me?",window);    
    window->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
    window->setAttribute(Qt::WA_TranslucentBackground, true);

    //comment folloing code and everything will work fine.
    auto quick = new QQuickWidget(window);
    quick->setSource(QUrl("qrc:/main.qml"));
    quick->move(40,40);

    window->show();

    return a.exec();
}

Edit: I am trying to create QQuickWidgetwithout a parent. And make it look like a built-in widget.

auto quick = new QQuickWidget();
quick->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
quick->setAttribute(Qt::WA_TranslucentBackground, true);
quick->setClearColor(Qt::transparent);

But there is a serious problem. I can not click on its background, although it is transparent. I checked that the transparent background QWidgetcan be clicked.

Edit2: after I rebooted the computer, quickwidget again became invisible. Wtf

Edit3: Qt5.5.0 looks fine.

+4
source share

Source: https://habr.com/ru/post/1605953/


All Articles