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 (QGLWindow) functionality in QDeclarativeView
Qt 6.11 is out! See what's new in the release blog

OpenGL (QGLWindow) functionality in QDeclarativeView

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 5.2k 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.
  • W Offline
    W Offline
    wspilot
    wrote on last edited by
    #1

    Hi,
    I am working on a project for Sailfish OS (Qt 4.8) app.
    I need to integrate openGL into QML using a QDeclarativeView.
    Seen and tried the examples as shown in the Qt Forums.
    They all:
    set a QGLWidget as the viewport of the QDeclarativeView;
    Use a QDeclarativeItem and re-implement the paint function with:
    beginNativePainting() etc.;
    qmlRegisterType is used to bind the QDeclarativeItem class to a QML type.

    This looks nice (as in the examples) if you have some simple fixed pipeline rendering, but I need to use a lot of extra openGL functionality (like setAttribute, QGLShaderProgram, compileSourceCode, etc.).
    This is all neatly implemented in QGLWidget, but not in QDeclarativeItem which is now responsible for the openGL rendering/painting.
    So, is there a way have the QGLWidget available / accessible in QML?
    Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adrien Leravat
      wrote on last edited by
      #2

      This may not be the answer you're looking for, but the kind of things you're trying to do is possible with little effort with QtQuick 2 (Qt5). With QtQuick2 your more or less directly manipulate OpenGL data in custom Qml items.

      Using Qt 4.8, i'm not sure how you could do that without creating your own QPainter+QGLWidget+QDeclarativeView+QDeclarativeItem to support custom advanced painting commands. And very likely need to modify private implementation of those classes too.

      Adeneo Embedded - www.adeneo-embedded.com

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wspilot
        wrote on last edited by
        #3

        I have now made a MyDeclarativeView class derived from QDeclarativeView.
        Next I have added my QGLWindow as a child Widget to MyDeclarativeView.
        Further MyDeclarativeView sets a QGraphicsScene (setScene) to which I add QML items (addItem).
        Seems to work, but I am not sure if this is all sound....

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adrien Leravat
          wrote on last edited by
          #4

          (I guess you meant QDeclarative(View))

          Yes you can implement it manually that way. I'm not sure if making the QGLWindow a child of your view will render it or not. If not, you may want to make it a sibling of your View.

          I'm very curious about it if you succeed, interesting problem.

          Adeneo Embedded - www.adeneo-embedded.com

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wspilot
            wrote on last edited by
            #5

            QDeclarative(View) corrected. Sorry.
            Yes it works as desktop app.
            Only had to:
            @view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
            view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);@
            (view = MyDeclarativeView object).

            Now try it on Sailfish...
            I'll report back.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              wspilot
              wrote on last edited by
              #6

              Does not crash on Sailfish, but QGLWindow stays black...
              Possibly a openGL issue with the simulator.
              And had to comment out:
              #ifdef HAS_BOOSTER
              view = MDeclarativeCache::qDeclarativeView();
              #else...
              because I have my own QDeclarativeView derived class.
              I'll ask about it on the Sailfish list.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wspilot
                wrote on last edited by
                #7

                Just found out that signals in QML (to c++) don't work.
                Changed QDeclarativeView->setScene etc. to QDeclarativeView->setSource
                Now it works.
                QGLWindow overlaps qml page.

                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