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. OpenGL rendering to a specifc QML item
Forum Updated to NodeBB v4.3 + New Features

OpenGL rendering to a specifc QML item

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 4 Posters 4.8k Views 1 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.
  • B Offline
    B Offline
    blueskin.neo
    wrote on last edited by
    #1

    Hi,
    I have a QML file which contains a layout of QML items and now I want one of those items to be a QGLWidget. i.e. I want to render to a specific QML item.

    Is anyone aware of how to do this? Thank you.

    CV

    1 Reply Last reply
    0
    • M Offline
      M Offline
      minimoog77
      wrote on last edited by
      #2

      I don't think it's possible, but you could use FBO instead.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrasser
        wrote on last edited by
        #3

        Hi,

        I'd suggest setting the viewport of your QDeclarativeView to a QGLWidget. You can then use GL within your item's paint() method. (typically using QPainter::beginNativePainting() and QPainter::endNativePainting()). Is this type of approach viable for what you need to do?

        Regards,
        Michael

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blueskin.neo
          wrote on last edited by
          #4

          Hi Michael,

          If I set the viewport to QGLWidget then the entire DeclarativeView becomes the paint area right. i.e. when I paint inside QGLWidget::paintGL() then I'd be painting to the whole view and not a specific region (i.e. QDeclarativeItem).
          I have a list of QDeclarativeItems from MyQDeclarativeView.rootObject()->children();
          And trying to figure out how I can make one of these items as a paint area for my GLWidget.
          Thanks for your reply.

          CV

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blueskin.neo
            wrote on last edited by
            #5

            Hi Michael,

            I am kind of successful but not completely, I created a new DeclarativeItem and set its graphicsproxywidget's widget to my glwidget as below

            @class GLWidgetDeclarativeItem : public QDeclarativeItem
            {
            Q_OBJECT
            public:
            GLWidgetDeclarativeItem(QDeclarativeItem *parent =0)
            : QDeclarativeItem(parent)
            {
            setFlag(QGraphicsItem::ItemHasNoContents, false);
            QDeclarativeItem::setFlag(QGraphicsItem::ItemHasNoContents, false);
            m_glWidget = new GLWidget();
            m_proxy = new QGraphicsProxyWidget(this);
            m_proxy->setWidget(m_glWidget);
            m_glWidget->show();
            m_proxy->show();
            }

            private:
            GLWidget *m_glWidget;
            QGraphicsProxyWidget *m_proxy;
            };
            @

            And in my main when I create a declarativeview, I find the QML item and pass it as parent to GLWidgetDeclarativeItem as
            @
            int main(int argc, char argv[])
            {
            QApplication app(argc, argv);
            QDeclarativeView qmlview (QUrl::fromLocalFile("qml/GLInsideQML/main.qml"));
            QDeclarativeItem item = qobject_cast<QDeclarativeItem>
            (qmlview.rootObject()->findChild <QObject
            > ("GLArea"));
            GLWidgetDeclarativeItem glItem(item);
            qmlview.show();
            return app.exec();
            }
            @

            Now, the only problem is I don't see the painting happening, I get the mouseEvents invoked in my GlWidget when I click. But no painting :(
            "Here's the complete test code":https://sites.google.com/site/blueskinneo/home/GLInsideQMLTest.zip?attredirects=0&d=1
            Let me know if you find anything wrong.

            Thanks
            CV

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbrasser
              wrote on last edited by
              #6

              Hi,

              [quote author="blueskin.neo" date="1318962508"]
              If I set the viewport to QGLWidget then the entire DeclarativeView becomes the paint area right. i.e. when I paint inside QGLWidget::paintGL() then I'd be painting to the whole view and not a specific region (i.e. QDeclarativeItem).[/quote]

              You shouldn't need to worry about QGLWidget::paintGL() if you are creating a single custom item. You can use raw GL inside of your QDeclarativeItem subclass' paint() function instead (wrapped in the calls I mention above), as long as the viewport for the view is a QGLWidget.

              Here are a couple other threads that might explain this a bit better:

              • http://developer.qt.nokia.com/forums/viewthread/4109
              • http://developer.qt.nokia.com/forums/viewthread/8374

              Hope that helps.

              Regards,
              Michael

              1 Reply Last reply
              0
              • D Offline
                D Offline
                diro
                wrote on last edited by
                #7

                [quote author="blueskin.neo" date="1318962508"]Hi Michael,

                If I set the viewport to QGLWidget then the entire DeclarativeView becomes the paint area right. i.e. when I paint inside QGLWidget::paintGL() then I'd be painting to the whole view and not a specific region (i.e. QDeclarativeItem).
                I have a list of QDeclarativeItems from MyQDeclarativeView.rootObject()->children();
                And trying to figure out how I can make one of these items as a paint area for my GLWidget.
                Thanks for your reply.

                CV[/quote]
                I agree with mbrasser!
                In my real project, the painting could be restricted in the specific region. I created a C++ extension inherited from QDeclarativeItem (so, it is QGraphicsItem rathan than QGLWidget), and the extension works well with opengl native commands. I just overwrite the paint() function in QDeclarativeItem, not the paintGL() in QGLWidget.

                1 Reply Last reply
                0

                • Login

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