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. Save QQuickView screen to image
QtWS25 Last Chance

Save QQuickView screen to image

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

    I am trying to save a QQuickView as an image but with no success. I tried the obvious approach:

    @view->renderTarget()->toImage().save(fileName);@

    However this crashes, and the reason for this is probably that renderTarget() returns a null pointer.

    Am I doing something wrong? Or maybe there is a better way?

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

      Try:

      @
      QImage image = view->grabWindow();
      @

      This function might not work if the window is not visible.
      "QQuickWindow::grabWindow()":http://qt-project.org/doc/qt-5.0/qtquick/qquickwindow.html#grabWindow

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        Thanks, this works, strange why the other method doesn't.

        Anyway, what if I want to save only a particular QML object as an image, would that be possible?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          melghawi
          wrote on last edited by
          #4

          I'm not sure if there is a direct way to do this but you can grab the entire window and then cut out the bit you want.

          Try this:

          @
          QQuickWindow *window = item->window();
          QImage grabbed = window->grabWindow();
          QRectF rf(item->x(), item->y(), item->width(), item->height());
          rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height()));
          QImage itemImage = grabbed.copy(rf.toAlignedRect());
          @

          Read more "here":http://qt-project.org/forums/viewthread/18371.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            Yeah that could work in a limiter range of cases, but it won't work for nested and layered structures. I'd rather be able to get the objects pixmap from the final stage of the framebuffer before it is blended and composed in the scene.

            Plus, the grabWindow() method is brutally slow and even in the doc is labeled as a performance problem.

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

              Yes that is true. You can get a texture from a "QQuickItem":http://qt-project.org/doc/qt-5.0/qtquick/qquickitem.html only if it is a "textureProvider":http://qt-project.org/doc/qt-5.0/qtquick/qquickitem.html#textureProvider. At a quick glance, there doesn't seem to be anything that exposes an objects' pixmap.

              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