Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Saving widget in image
Forum Update on Monday, May 27th 2025

Saving widget in image

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.4k 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.
  • O Offline
    O Offline
    Omri
    wrote on 25 Jul 2015, 18:49 last edited by
    #1

    hello,
    how can I save what's appearing on a widget's window?
    i found 2 solutions for that that didn't work:

    1. ui->widget->grab().save("image.png");

    2. QPixmap originalPixmap;

      originalPixmap = QPixmap::grabWidget(tabWidget->currentWidget());

      QString format = "png";

      QString fileName = "myshot.png";

      originalPixmap.save(fileName, format.toAscii());

    I want to make a screenshot of a video that is presented in the widget.
    Is there a better way to save the widget or am i doing something wrong?
    Is there a way to "manually" save a part of the screen(where the widget is located)?

    thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 25 Jul 2015, 23:31 last edited by
      #2

      @Omri said:

      Hi and welcome

      ui->widget->grab().save("image.png");

      Does work as expected here. (win 7 , Qt 5.5) for a normal control.

      But If you are showing live video, it is often not working as one would expect.

      You could look into exporting a frame from the video
      http://stackoverflow.com/questions/30800772/how-to-grab-video-frames-in-qt
      or try the
      http://doc.qt.io/qt-5/qtwidgets-desktop-screenshot-example.html
      and see if grabbing the whole screen, does show your video.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        Omri
        wrote on 26 Jul 2015, 15:21 last edited by
        #3

        Thank you.
        these 2 lines of code did the job:

        QScreen *screen = QGuiApplication::primaryScreen();
        
        originalPixmap = screen->grabWindow(ui->widget->winId());
        
        1 Reply Last reply
        0

        1/3

        25 Jul 2015, 18:49

        • Login

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