QQuickView/ QQuickWidget embeded in opacity QWidget



  • Hi! I have problem with rendering QML using QQuickView /QQiuickWidget embeded in QWidget with attribute Qt::WA_TranslucentBackground. Usual widgets behavior is correct. Any ideas?

    Container widget has this:

    setWindowFlags(Qt::FramelessWindowHint | Qt::Tool );
    setAttribute(Qt::WA_TranslucentBackground);
    

    QML file looking like this:

    import QtQuick 2.0 (or 1.0 for QDeclarativeView)
    
    Rectangle {
        id: window
        color: "red"
    }
    
    

    Working code sample:

    QDeclarativeView *view = new QDeclarativeView(QUrl("qrc:/qml/qmlcontent"));
    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    

    Not working code sample:

    QQuickWidget *view = new QQuickWidget(QUrl("qrc:/qml/qmlcontent"));
    view->setResizeMode(QQuickWidget::SizeRootObjectToView);
    

    One more not working code sample:

    QQuickView *view = new QQuickView();
    view->setResizeMode(QQuickView::SizeRootObjectToView);
    
    QWidget *container = QWidget::createWindowContainer(view,  containerWidget);
    
    view->setSource(QUrl("qrc:/qml/qmlcontent"));
    

  • Moderators

    Hi @xumuk, That I guess is the limitation with both QQuickWidget and createWindowContainer as documented here.

    Putting other widgets underneath and making the QQuickWidget transparent will not lead to the expected results: the widgets underneath will not be visible. This is because in practice the QQuickWidget is drawn before all other regular, non-OpenGL widgets, and so see-through types of solutions are not feasible.

    With QtQuick 1.x it was different. It used the traditional QGraphics* backend. QtQuick 2.x uses Scenegraph based on OpenGL.



  • Please refer here for more information.
    Besides, you may want to try running this example:
    <Qt_Installatin_Folder>\5.4\Src\qtdeclarative\examples\quick\quickwidgets\qquickviewcomparison



  • Thanks a lot for answers! But how to do semitransparent QQuickWidget on Windows/Linux using QML to get similar result like i can do this with:

    QWidget *w = new QWidget;
    w->setWindowFlags(Qt::FramelessWindowHint);
    w->setAttribute(Qt::WA_TranslucentBackground);
    w->resize(500, 400);
    
    QHBoxLayout *layout = new QHBoxLayout(w);
    layout->setContentsMargins(0,0,0,0);
    
    QWidget *s = new QWidget(w);
    s->setStyleSheet("background-color: rgba(128,128,128,128)");
    
    layout->addWidget(s);
    
    w->show();
    

  • Moderators

    @xumuk As said earlier it is a limitation. But if you still need it you should have a look at the 2nd and 3rd paragraph in the link which I posted earlier. Basically you will have to do this:

    QQuickWidget *wd = new QQuickWidget(this);
    wd->setAttribute(Qt::WA_AlwaysStackOnTop);
    wd->setClearColor(Qt::transparent);
    
    //and the opacity can be set in QML istelf for eg. for a Rectangle
    Rectangle {
        width: 300
        height: 300
        color: "green"
        opacity: 0.5
    }
    

    If you load this QML in the QQuickWIdget and put a QWidget in background it should be visible.



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