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. Render QML element as bitmap
Forum Updated to NodeBB v4.3 + New Features

Render QML element as bitmap

Scheduled Pinned Locked Moved QML and Qt Quick
10 Posts 4 Posters 4.3k 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.
  • Z Offline
    Z Offline
    zamberson
    wrote on last edited by
    #1

    I'm trying to save a QML element as an image file following the method suggested in "this thread":http://qt-project.org/forums/viewthread/3948

    The problem seems to be a cast which isn't occurring or I'm casting to something deprecated.

    Can someone point a way of solving the cast or a better method to render a QML element as an image?

    @void Capturer::save(QObject *imageObj)
    {
    if(!imageObj)
    {
    qDebug() << "imageObj is NULL";
    return;
    } else {
    qDebug() << "imageObj is: " << imageObj;
    qDebug() << "imageObj parent is: " << imageObj->parent();
    }

    QGraphicsObject *item = qobject_cast<QGraphicsObject*>(imageObj);
    
    if (!item)
    {
        qDebug() << "GraphicsObject is NULL";
        return;
    }
    

    }

    // Outputs:
    //
    // imageObj is: QQuickImage(0x102c4dd10)
    // imageObj parent is: QQuickColumn(0x102c4d940)
    // GraphicsObject is NULL @

    Thanks!

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zamberson
      wrote on last edited by
      #2

      Sorry. I'm bumping.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThinkDeep
        wrote on last edited by
        #3

        Hi,
        how did you solve the problem? I have tha same.

        Thank you.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          Maybe another suggestion: you can render a QQuickWindow to a custom QOpenGLFramebufferObject, I guess there is a way to save the content of that FBO to an image?
          http://qt-project.org/doc/qt-5/qquickwindow.html#setRenderTarget

          1 Reply Last reply
          0
          • T Offline
            T Offline
            ThinkDeep
            wrote on last edited by
            #5

            I wanted to work with image data (for the first time saving) and than manipulate with it (e.g. with openCV), but still wanted to make gui with QML. But the binding is quiet messy. Is something like this even possible?
            I did not find any good tutorial or example to do this.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tân Ngọc Đỗ
              wrote on last edited by
              #6

              Is there anyone has some idea or solution ?

              1 Reply Last reply
              0
              • X Offline
                X Offline
                Xander84
                wrote on last edited by
                #7

                I found a simpler solution than my suggestion before, you can use "QQuickWindow::grabWindow()":http://qt-project.org/doc/qt-5/qquickwindow.html#grabWindow to get an QImage of the entire window.
                If you want an image of just a specific element inside of that window you can crop the image to that element, positions should be available to do that problematically. That is at least the easiest way i can thin of, since you can't get an image of a single QQuickItem, but the whole window only as far as I know.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Tân Ngọc Đỗ
                  wrote on last edited by
                  #8

                  That's a good idea. Do we have to obtain the top QQuickItem To get QQuickWindow ?

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    Xander84
                    wrote on last edited by
                    #9

                    That depends on how you create your QML application I think.
                    With the default Qt Quick 2 template in Qt Creator, you can just call the method directly:
                    @
                    QtQuick2ApplicationViewer viewer;
                    QImage img = viewer.grabWindow();
                    @
                    because QtQuick2ApplicationViewer inherits from QQuickView and QQuickView from QQuickWindow. :)

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      Tân Ngọc Đỗ
                      wrote on last edited by
                      #10

                      Yes! Maybe I will use some tricks to do that. If I have any problem I will ask you. Thank you so much :)

                      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