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. Printscreen QML item C++
Forum Update on Monday, May 27th 2025

Printscreen QML item C++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 4 Posters 1.5k 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.
  • M Offline
    M Offline
    MartinD
    wrote on last edited by
    #1

    Is it possible to grab printscreen of QML item without saving it to file? I don't want to save image to file with myQmlItem.grabToImage(function(result) { result.saveToFile("myImage.png"); }); because I will use the image in underlying C++ code. Of course, I can save image to file, then read it back in C++ but it would be good if I can access the image in C++ directly without storing it and reading back.

    raven-worxR 1 Reply Last reply
    0
    • M MartinD

      Is it possible to grab printscreen of QML item without saving it to file? I don't want to save image to file with myQmlItem.grabToImage(function(result) { result.saveToFile("myImage.png"); }); because I will use the image in underlying C++ code. Of course, I can save image to file, then read it back in C++ but it would be good if I can access the image in C++ directly without storing it and reading back.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @MartinD

      QML:

      myItem.grabToImage( function(result) {
                  myObj.processQMLImage(result);
              } );
      

      C++

      void processQMLImage(QObject* imageObj)
      {
          if( QQuickItemGrabResult* item = qobject_cast<QQuickItemGrabResult*>(imageObj) )
          {
                QImage image = item->image();
                //.....
          }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        @MartinD Or you can just do it directly by calling follwing function from QML:

        void capture(QQuickItem *item)
        {
            auto grabResult = item->grabToImage(QSize(50,50));
        
            connect(grabResult.data(), &QQuickItemGrabResult::ready, [=]() {
                QImage image = grabResult.data()->image();
            });
        }
        

        157

        1 Reply Last reply
        3
        • M Offline
          M Offline
          MartinD
          wrote on last edited by
          #4

          Thanks, very useful!

          1 Reply Last reply
          1
          • H Offline
            H Offline
            huxiyu
            wrote on last edited by
            #5

            I want grab QML item to save video. eg: mp4
            Is there a way to record the layer ?

            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