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. Translucent background not rendering correctly in Qt6 with hardware rendering but works with Software rendering
Forum Updated to NodeBB v4.3 + New Features

Translucent background not rendering correctly in Qt6 with hardware rendering but works with Software rendering

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 3 Posters 1.8k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    Muhammad Hassan Shahid
    wrote on 27 Feb 2023, 16:15 last edited by
    #1

    I have a blue main window on top of which I draw a Qt Quick Widget. I want the functionality that when the Qt Quick Widget is displayed the area of the main window turns translucent so the user focuses on the Quick widget. For that I am using these commands

    m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
    m_quickWidget->setClearColor(Qt::transparent);
    m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);

    By default, the result looks like this, you can see that the background is not transparent anymore but greyed out.

    6de83842-ae18-4275-89ed-7f0cd7b28082-image.png

    But when I change the rendering to software with QQuickWindow::setSceneGraphBackend("software"); It works correctly as below.

    81f31b82-85c2-4143-a6e2-d633989e50c1-image.png

    Software rendering is slow, I want it to work with hardware rendering. Does anybody know the solution to this or have encountered this problem before with Qt6? Or is there some other way to make the background transparent which works with hardware rendering?

    M 1 Reply Last reply 27 Feb 2023, 19:24
    0
    • M Muhammad Hassan Shahid
      27 Feb 2023, 16:15

      I have a blue main window on top of which I draw a Qt Quick Widget. I want the functionality that when the Qt Quick Widget is displayed the area of the main window turns translucent so the user focuses on the Quick widget. For that I am using these commands

      m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
      m_quickWidget->setClearColor(Qt::transparent);
      m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);

      By default, the result looks like this, you can see that the background is not transparent anymore but greyed out.

      6de83842-ae18-4275-89ed-7f0cd7b28082-image.png

      But when I change the rendering to software with QQuickWindow::setSceneGraphBackend("software"); It works correctly as below.

      81f31b82-85c2-4143-a6e2-d633989e50c1-image.png

      Software rendering is slow, I want it to work with hardware rendering. Does anybody know the solution to this or have encountered this problem before with Qt6? Or is there some other way to make the background transparent which works with hardware rendering?

      M Offline
      M Offline
      Muhammad Hassan Shahid
      wrote on 27 Feb 2023, 19:24 last edited by
      #2

      This is the code to reproduce it

      #include <QQuickWidget>
      #include <QQuickItem>
      #include <QQmlError>
      #include <QtWidgets>

      class MainWindow : public QMainWindow {
      Q_OBJECT
      public:
      MainWindow();
      private:
      QQuickWidget *m_quickWidget;
      };

      MainWindow::MainWindow()
      : m_quickWidget(new QQuickWidget)
      {
      setFixedSize(QSize(800,600));

        m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
        m_quickWidget->setClearColor(Qt::transparent);
      
        QUrl source("qrc:transparent.qml");
      
        m_quickWidget->resize(300,300);
        m_quickWidget->setWindowFlags(Qt::SplashScreen);
        m_quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
        m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
        m_quickWidget->setClearColor(Qt::transparent);
        m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
        m_quickWidget->setSource(source);
      
        QWidget *centralWidget = new QWidget();
        centralWidget->setStyleSheet("background-color: blue");
        QHBoxLayout *layout = new QHBoxLayout(centralWidget);
        layout->addWidget(m_quickWidget);
        setCentralWidget(centralWidget);
      

      }

      int main(int argc, char **argv)
      {
      QApplication app(argc, argv);

        MainWindow mainWindow;
        mainWindow.show();
      
        return app.exec();
      

      }

      #include "main.moc"

      J 1 Reply Last reply 27 Feb 2023, 19:37
      0
      • M Muhammad Hassan Shahid
        27 Feb 2023, 19:24

        This is the code to reproduce it

        #include <QQuickWidget>
        #include <QQuickItem>
        #include <QQmlError>
        #include <QtWidgets>

        class MainWindow : public QMainWindow {
        Q_OBJECT
        public:
        MainWindow();
        private:
        QQuickWidget *m_quickWidget;
        };

        MainWindow::MainWindow()
        : m_quickWidget(new QQuickWidget)
        {
        setFixedSize(QSize(800,600));

          m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
          m_quickWidget->setClearColor(Qt::transparent);
        
          QUrl source("qrc:transparent.qml");
        
          m_quickWidget->resize(300,300);
          m_quickWidget->setWindowFlags(Qt::SplashScreen);
          m_quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
          m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
          m_quickWidget->setClearColor(Qt::transparent);
          m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
          m_quickWidget->setSource(source);
        
          QWidget *centralWidget = new QWidget();
          centralWidget->setStyleSheet("background-color: blue");
          QHBoxLayout *layout = new QHBoxLayout(centralWidget);
          layout->addWidget(m_quickWidget);
          setCentralWidget(centralWidget);
        

        }

        int main(int argc, char **argv)
        {
        QApplication app(argc, argv);

          MainWindow mainWindow;
          mainWindow.show();
        
          return app.exec();
        

        }

        #include "main.moc"

        J Offline
        J Offline
        JoeCFD
        wrote on 27 Feb 2023, 19:37 last edited by
        #3

        @Muhammad-Hassan-Shahid
        Can you try:
        QQuickWindow::setSceneGraphBackend( QSGRendererInterface::OpenGL );

        The other options are here:
        https://doc.qt.io/qt-6/qsgrendererinterface.html

        M 1 Reply Last reply 28 Feb 2023, 14:56
        0
        • J JoeCFD
          27 Feb 2023, 19:37

          @Muhammad-Hassan-Shahid
          Can you try:
          QQuickWindow::setSceneGraphBackend( QSGRendererInterface::OpenGL );

          The other options are here:
          https://doc.qt.io/qt-6/qsgrendererinterface.html

          M Offline
          M Offline
          Muhammad Hassan Shahid
          wrote on 28 Feb 2023, 14:56 last edited by Muhammad Hassan Shahid
          #4

          @JoeCFD When I use the QSGRendererInterface enums, compiler gives me an error that it can't convert it to Qstring and indeed there is no overload of QQuickWindow::setSceneGraphBackend for parameter of type QSGRendererInterface::GraphicsApi

          J 1 Reply Last reply 28 Feb 2023, 15:25
          0
          • M Muhammad Hassan Shahid
            28 Feb 2023, 14:56

            @JoeCFD When I use the QSGRendererInterface enums, compiler gives me an error that it can't convert it to Qstring and indeed there is no overload of QQuickWindow::setSceneGraphBackend for parameter of type QSGRendererInterface::GraphicsApi

            J Offline
            J Offline
            JoeCFD
            wrote on 28 Feb 2023, 15:25 last edited by JoeCFD
            #5

            @Muhammad-Hassan-Shahid Sorry you call this one
            void QQuickWindow::setGraphicsApi(QSGRendererInterface::GraphicsApi api)

            The source code is here
            https://codebrowser.dev/qt6/qtdeclarative/src/quick/items/qquickwindow.cpp.html
            check line 3773
            there are only two options: OpenVG may be the one you need.

                // Special cases: these are different scenegraph backends.
                switch (api) {
                case QSGRendererInterface::Software:
                    setSceneGraphBackend(QStringLiteral("software"));
                    break;
                case QSGRendererInterface::OpenVG:
                    setSceneGraphBackend(QStringLiteral("openvg"));
                    break;
                default:
                    break;
                }
            

            https://doc.qt.io/qt-6/qtquick-visualcanvas-adaptations-openvg.html

            M 1 Reply Last reply 28 Feb 2023, 16:24
            0
            • J JoeCFD
              28 Feb 2023, 15:25

              @Muhammad-Hassan-Shahid Sorry you call this one
              void QQuickWindow::setGraphicsApi(QSGRendererInterface::GraphicsApi api)

              The source code is here
              https://codebrowser.dev/qt6/qtdeclarative/src/quick/items/qquickwindow.cpp.html
              check line 3773
              there are only two options: OpenVG may be the one you need.

                  // Special cases: these are different scenegraph backends.
                  switch (api) {
                  case QSGRendererInterface::Software:
                      setSceneGraphBackend(QStringLiteral("software"));
                      break;
                  case QSGRendererInterface::OpenVG:
                      setSceneGraphBackend(QStringLiteral("openvg"));
                      break;
                  default:
                      break;
                  }
              

              https://doc.qt.io/qt-6/qtquick-visualcanvas-adaptations-openvg.html

              M Offline
              M Offline
              Muhammad Hassan Shahid
              wrote on 28 Feb 2023, 16:24 last edited by
              #6

              @JoeCFD I tried OpenVG but the result the same as the hardware rendering one. It only works with the software rendering.

              J 1 Reply Last reply 28 Feb 2023, 16:29
              0
              • M Muhammad Hassan Shahid
                28 Feb 2023, 16:24

                @JoeCFD I tried OpenVG but the result the same as the hardware rendering one. It only works with the software rendering.

                J Offline
                J Offline
                JoeCFD
                wrote on 28 Feb 2023, 16:29 last edited by JoeCFD
                #7

                @Muhammad-Hassan-Shahid
                check if the backend setting is correct.
                from here:
                QString QQuickWindow::sceneGraphBackend()

                https://www.qt.io/blog/2017/03/31/qt-quick-openvg

                M 1 Reply Last reply 28 Feb 2023, 16:42
                0
                • J JoeCFD
                  28 Feb 2023, 16:29

                  @Muhammad-Hassan-Shahid
                  check if the backend setting is correct.
                  from here:
                  QString QQuickWindow::sceneGraphBackend()

                  https://www.qt.io/blog/2017/03/31/qt-quick-openvg

                  M Offline
                  M Offline
                  Muhammad Hassan Shahid
                  wrote on 28 Feb 2023, 16:42 last edited by
                  #8

                  @JoeCFD The function returns OpenVG but the Qt complains "Could not create scene graph context for backend 'openvg' - check that plugins are installed correctly"

                  J 2 Replies Last reply 28 Feb 2023, 17:03
                  0
                  • M Muhammad Hassan Shahid
                    28 Feb 2023, 16:42

                    @JoeCFD The function returns OpenVG but the Qt complains "Could not create scene graph context for backend 'openvg' - check that plugins are installed correctly"

                    J Offline
                    J Offline
                    JoeCFD
                    wrote on 28 Feb 2023, 17:03 last edited by JoeCFD
                    #9

                    @Muhammad-Hassan-Shahid said in Translucent background not rendering correctly in Qt6 with hardware rendering but works with Software rendering:

                    Could not create scene graph context for backend 'openvg' - check that plugins are installed correctly

                    The messages are not very helpful. Which plugins are not installed properly? You have to figure that out. I do not know it either. But you know the reasons now.

                    M 1 Reply Last reply 1 Mar 2023, 16:31
                    0
                    • J JoeCFD
                      28 Feb 2023, 17:03

                      @Muhammad-Hassan-Shahid said in Translucent background not rendering correctly in Qt6 with hardware rendering but works with Software rendering:

                      Could not create scene graph context for backend 'openvg' - check that plugins are installed correctly

                      The messages are not very helpful. Which plugins are not installed properly? You have to figure that out. I do not know it either. But you know the reasons now.

                      M Offline
                      M Offline
                      Muhammad Hassan Shahid
                      wrote on 1 Mar 2023, 16:31 last edited by
                      #10

                      @JoeCFD The error is from Qt itself and it doesn't say which plugins exactly. Is there another way this functionality can be achieved in Qt which works with hardware rendering?

                      1 Reply Last reply
                      0
                      • M Muhammad Hassan Shahid
                        28 Feb 2023, 16:42

                        @JoeCFD The function returns OpenVG but the Qt complains "Could not create scene graph context for backend 'openvg' - check that plugins are installed correctly"

                        J Offline
                        J Offline
                        JoeCFD
                        wrote on 1 Mar 2023, 17:39 last edited by JoeCFD 3 Jan 2023, 17:40
                        #11

                        @Muhammad-Hassan-Shahid message in running time or compiling time?
                        Linux or Windows?

                        M 1 Reply Last reply 2 Mar 2023, 16:35
                        0
                        • J JoeCFD
                          1 Mar 2023, 17:39

                          @Muhammad-Hassan-Shahid message in running time or compiling time?
                          Linux or Windows?

                          M Offline
                          M Offline
                          Muhammad Hassan Shahid
                          wrote on 2 Mar 2023, 16:35 last edited by
                          #12

                          @JoeCFD runtime error on windows

                          M 1 Reply Last reply 3 Mar 2023, 15:59
                          0
                          • M Muhammad Hassan Shahid
                            2 Mar 2023, 16:35

                            @JoeCFD runtime error on windows

                            M Offline
                            M Offline
                            Muhammad Hassan Shahid
                            wrote on 3 Mar 2023, 15:59 last edited by
                            #13

                            @Muhammad-Hassan-Shahid The solution is to set ui->quickWidget->quickWindow()->setColor(QColor(0,0,0,0)); after the main window has been rendered to bypass this issue with hardware rendering but this problem should be solved by Qt in the future. There shouldn't be a need to do something like this in the first place.

                            This is the code to reproduce it

                            #include <QQuickWidget>
                            #include <QQuickItem>
                            #include <QQmlError>
                            #include <QtWidgets>

                            class MainWindow : public QMainWindow {
                            Q_OBJECT
                            public:
                            MainWindow();
                            QQuickWidget *m_quickWidget;
                            };

                            MainWindow::MainWindow()
                            : m_quickWidget(new QQuickWidget)
                            {
                            setFixedSize(QSize(800,600));

                            m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
                            m_quickWidget->setClearColor(Qt::transparent);

                            QUrl source("qrc:transparent.qml");

                            m_quickWidget->resize(300,300);
                            m_quickWidget->setWindowFlags(Qt::SplashScreen);
                            m_quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
                            m_quickWidget->setAttribute(Qt::WA_TranslucentBackground);
                            m_quickWidget->setClearColor(Qt::transparent);
                            m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
                            m_quickWidget->setSource(source);

                            QWidget *centralWidget = new QWidget();
                            centralWidget->setStyleSheet("background-color: blue");
                            QHBoxLayout *layout = new QHBoxLayout(centralWidget);
                            layout->addWidget(m_quickWidget);
                            setCentralWidget(centralWidget);
                            }

                            int main(int argc, char **argv)
                            {
                            QApplication app(argc, argv);

                            MainWindow mainWindow;
                            mainWindow.show();

                            mainWindow.m_quickWidget->quickWindow()->setColor(QColor(0,0,0,0));

                            return app.exec();
                            }

                            #include "main.moc"

                            1 Reply Last reply
                            0
                            • M Muhammad Hassan Shahid has marked this topic as solved on 3 Mar 2023, 15:59
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 3 Mar 2023, 19:34 last edited by
                              #14

                              You should open a ticket on the bug report system to make it known to Qt developers.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0

                              1/14

                              27 Feb 2023, 16:15

                              • Login

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