I have a problem making the QQuickWidget
background transparent.
I want to place a QQuickWidget
underneath a QWidget
. The QQuickWidget
uses a source qml file. When I worked with Qt 4.8, I used QDeclarativeView
. Porting from Qt 4 to Qt 5, QDeclarativeView
is no longer used. Therefore, I am usingQQuickWidget
instead of QDeclarativeView
, as follows:
QWidget *mainWidget = new QWidget();
mainWidget->setStyleSheet("background-image: url(:/background.png);");
QQuickWidget *quick = new QQuickWidget(mainWidget);
quick->setAttribute(Qt::WA_TranslucentBackground, true);
quick->setAttribute(Qt::WA_AlwaysStackOnTop, true);
quick->setClearColor(Qt::transparent);
quick->setSource(QUrl("qrc:/image.qml"));
QWidget *topWidget = new QWidget(mainWidget);
topWidget->setStyleSheet("background-image: url(:/semitransparent.png);");
If I do:
setAttribute(Qt::WA_AlwaysStackOnTop, true);
then the background becomes transparent, but breaks the stacking order involving the other widgets underneath the QQuickWidget
inside the same window.
I want to make a QQuickWidget
transparent when it is underneath a QWidget
. Is this possible? If not, what workarounds do you suggest?
(1) This is mainWidget's background image:
(2) This is QQuickWidget's background. qml file use this image:
(3) This is topWidget's background image:
(4) What I want:
(5) What I get when I set WA_AlwaysStackOnTop
as false:
(6) What I get when I set WA_AlwaysStackOnTop
as true: