Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQuickView/ QQuickWidget embeded in opacity QWidget
QtWS25 Last Chance

QQuickView/ QQuickWidget embeded in opacity QWidget

Scheduled Pinned Locked Moved QML and Qt Quick
qmlqt5qquickwidgetqtquickqquickviewqdeclarativevie
5 Posts 3 Posters 6.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xumuk
    wrote on 15 May 2015, 12:22 last edited by
    #1

    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"));
    
    P 1 Reply Last reply 17 May 2015, 03:55
    1
    • X xumuk
      15 May 2015, 12:22

      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"));
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 17 May 2015, 03:55 last edited by
      #2

      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.

      157

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Tadinu
        wrote on 18 May 2015, 07:38 last edited by
        #3

        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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xumuk
          wrote on 18 May 2015, 08:51 last edited by xumuk
          #4

          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();
          
          P 1 Reply Last reply 18 May 2015, 12:29
          0
          • X xumuk
            18 May 2015, 08:51

            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();
            
            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 18 May 2015, 12:29 last edited by p3c0
            #5

            @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.

            157

            1 Reply Last reply
            1

            5/5

            18 May 2015, 12:29

            • Login

            • Login or register to search.
            5 out of 5
            • First post
              5/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved