Important: Please read the Qt Code of Conduct -

Saving widget in image

  • 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";, 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)?


  • Lifetime Qt Champion

    @Omri said:

    Hi and welcome


    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
    or try the
    and see if grabbing the whole screen, does show your video.

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

    QScreen *screen = QGuiApplication::primaryScreen();
    originalPixmap = screen->grabWindow(ui->widget->winId());

Log in to reply