Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGLWidget doesn't work with QQuickWidget
Forum Updated to NodeBB v4.3 + New Features

QOpenGLWidget doesn't work with QQuickWidget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 966 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 18 Aug 2023, 00:05 last edited by A Former User
    #1

    Hello.

    I am using Qt 6.5.0 under Windows 10.

    I am trying to use OpenGL and QML at the same time.

    So, I made a simple test project based on the Qt Quick Widget Example in Qt Creator 10.0.1.
    (C:\Qt\Examples\Qt-6.5.0\quick\quickwidgets\quickwidget)

    What I did is adding MyWidget class and calling addSubWindow(my_widget);

     QUrl source("qrc:quickwidget/rotatingsquare.qml");
    
     connect(m_quickWidget, &QQuickWidget::statusChanged,
             this, &MainWindow::quickWidgetStatusChanged);
     connect(m_quickWidget, &QQuickWidget::sceneGraphError,
             this, &MainWindow::sceneGraphError);
     m_quickWidget->resize(300,300);
     m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
     m_quickWidget->setSource(source);
    
     centralWidget->addSubWindow(m_quickWidget);
    
     MyWidget* my_widget = new MyWidget(this);
     QSurfaceFormat format_;
     format_.setDepthBufferSize(24);
     format_.setStencilBufferSize(8);
     format_.setVersion(3, 2);
     format_.setProfile(QSurfaceFormat::CoreProfile);
     my_widget->setFormat(format_);
    
     my_widget->setMinimumSize(300,300);
     centralWidget->addSubWindow(my_widget);
    
     setCentralWidget(centralWidget);
    

    When I try to create QOpenGLWidget and QQuickWidget at the same time, I get below error message and OpenGL Window is not rendered properly.

    The top-level window is not using OpenGL for composition, 'D3D11' is not compatible with QOpenGLWidget
    

    error_image.png

    ///centralWidget->addSubWindow(m_quickWidget);
    

    The QOpenGLWidget is correctly rendered if I comment out QQuickWidget.

    openGL_only.png
    Could you let me know how to use both widgets at the same time?

    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    #include <QtOpenGL>
    
    class MyWidget : public QOpenGLWidget, protected QOpenGLFunctions
    {
    public:
        MyWidget(QWidget* parent = nullptr);
    
    protected:
        void initializeGL() override;
        void resizeGL(int w, int h) override;
        void paintGL() override;
    
    };
    
    MyWidget::MyWidget(QWidget* parent)
        :QOpenGLWidget(parent)
    {
    
    }
    
    void MyWidget::initializeGL()
    {
        initializeOpenGLFunctions();
        glClearColor(1.0f, 0.1f, 1.0f, 1.0f);
    }
    void MyWidget::resizeGL(int w, int h)
    {
    
    }
    void MyWidget::paintGL()
    {
    
    }
    
    
    I 1 Reply Last reply 17 Sept 2023, 16:47
    1
    • ? A Former User
      18 Aug 2023, 00:05

      Hello.

      I am using Qt 6.5.0 under Windows 10.

      I am trying to use OpenGL and QML at the same time.

      So, I made a simple test project based on the Qt Quick Widget Example in Qt Creator 10.0.1.
      (C:\Qt\Examples\Qt-6.5.0\quick\quickwidgets\quickwidget)

      What I did is adding MyWidget class and calling addSubWindow(my_widget);

       QUrl source("qrc:quickwidget/rotatingsquare.qml");
      
       connect(m_quickWidget, &QQuickWidget::statusChanged,
               this, &MainWindow::quickWidgetStatusChanged);
       connect(m_quickWidget, &QQuickWidget::sceneGraphError,
               this, &MainWindow::sceneGraphError);
       m_quickWidget->resize(300,300);
       m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
       m_quickWidget->setSource(source);
      
       centralWidget->addSubWindow(m_quickWidget);
      
       MyWidget* my_widget = new MyWidget(this);
       QSurfaceFormat format_;
       format_.setDepthBufferSize(24);
       format_.setStencilBufferSize(8);
       format_.setVersion(3, 2);
       format_.setProfile(QSurfaceFormat::CoreProfile);
       my_widget->setFormat(format_);
      
       my_widget->setMinimumSize(300,300);
       centralWidget->addSubWindow(my_widget);
      
       setCentralWidget(centralWidget);
      

      When I try to create QOpenGLWidget and QQuickWidget at the same time, I get below error message and OpenGL Window is not rendered properly.

      The top-level window is not using OpenGL for composition, 'D3D11' is not compatible with QOpenGLWidget
      

      error_image.png

      ///centralWidget->addSubWindow(m_quickWidget);
      

      The QOpenGLWidget is correctly rendered if I comment out QQuickWidget.

      openGL_only.png
      Could you let me know how to use both widgets at the same time?

      #include <QOpenGLWidget>
      #include <QOpenGLFunctions>
      #include <QtOpenGL>
      
      class MyWidget : public QOpenGLWidget, protected QOpenGLFunctions
      {
      public:
          MyWidget(QWidget* parent = nullptr);
      
      protected:
          void initializeGL() override;
          void resizeGL(int w, int h) override;
          void paintGL() override;
      
      };
      
      MyWidget::MyWidget(QWidget* parent)
          :QOpenGLWidget(parent)
      {
      
      }
      
      void MyWidget::initializeGL()
      {
          initializeOpenGLFunctions();
          glClearColor(1.0f, 0.1f, 1.0f, 1.0f);
      }
      void MyWidget::resizeGL(int w, int h)
      {
      
      }
      void MyWidget::paintGL()
      {
      
      }
      
      
      I Offline
      I Offline
      Ioneater
      wrote on 17 Sept 2023, 16:47 last edited by
      #2

      @Hanabear This might be related to this post

      I had a similar situation where I wanted to use a QWebEngineView and pyqtgraph GLViewWidget in the same application.

      The line suggested in the other post solved this for me.

      QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

      or in my case (PyQt6)

      from PyQt6.QtQuick import QQuickWindow, QSGRendererInterface
      QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.OpenGL)

      ? 1 Reply Last reply 26 Oct 2023, 00:16
      1
      • I Ioneater
        17 Sept 2023, 16:47

        @Hanabear This might be related to this post

        I had a similar situation where I wanted to use a QWebEngineView and pyqtgraph GLViewWidget in the same application.

        The line suggested in the other post solved this for me.

        QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

        or in my case (PyQt6)

        from PyQt6.QtQuick import QQuickWindow, QSGRendererInterface
        QQuickWindow.setGraphicsApi(QSGRendererInterface.GraphicsApi.OpenGL)

        ? Offline
        ? Offline
        A Former User
        wrote on 26 Oct 2023, 00:16 last edited by
        #3

        @Ioneater Thank you for your information.

        I just created dummy QQuickWindow and called setGraphicsApi as you suggested.
        By calling graphicsApi before creating the first QQuickWidget, my problem has been solved.

        I also found a straightforward method not using dummy QQuickWindow by setting the QSG_RHI_BACKEND environment variable.

        Have a nice day.

        1 Reply Last reply
        1
        • System has marked this topic as solved on 26 Oct 2023, 00:16

        • Login

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