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. Taking screenshot of the dialog
Qt 6.11 is out! See what's new in the release blog

Taking screenshot of the dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 743 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.
  • G Offline
    G Offline
    GunkutA
    wrote on last edited by
    #1

    Hello, I am trying to take screenshot of QT dialog. For that I am using these lines:

    void secDialog::on_pushButton_clicked()
    {
        ui->status->setText("");
        QPixmap originalPixmap; // clear image for low memory situations
        QRect crop_rect(60, 230, 841, 170);
        QImage qt_screenshot = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId(),crop_rect.left(),crop_rect.top(),crop_rect.width(),crop_rect.height()).toImage();
        ui->status->setText("Screenshot is taken...");
    }
    

    I have 2 related questions:

    1. That does not capture any image. Is there any other way that I can use?
    2. I don't want user to press the button multiple times so I want to implement delay. But sleep() function looks like stopping all other operations. Is there a way I can achieve it by not using timers?

    P.S: I am really new to both QT and C++, sorry if these seem like easy questions. Thanks beforehand.

    jsulmJ 1 Reply Last reply
    0
    • G GunkutA

      Hello, I am trying to take screenshot of QT dialog. For that I am using these lines:

      void secDialog::on_pushButton_clicked()
      {
          ui->status->setText("");
          QPixmap originalPixmap; // clear image for low memory situations
          QRect crop_rect(60, 230, 841, 170);
          QImage qt_screenshot = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId(),crop_rect.left(),crop_rect.top(),crop_rect.width(),crop_rect.height()).toImage();
          ui->status->setText("Screenshot is taken...");
      }
      

      I have 2 related questions:

      1. That does not capture any image. Is there any other way that I can use?
      2. I don't want user to press the button multiple times so I want to implement delay. But sleep() function looks like stopping all other operations. Is there a way I can achieve it by not using timers?

      P.S: I am really new to both QT and C++, sorry if these seem like easy questions. Thanks beforehand.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @GunkutA You can do it way easier: https://stackoverflow.com/questions/10381854/how-to-create-screenshot-of-qwidget
      Use https://doc.qt.io/qt-5/qwidget.html#render

      QPixmap pixmap(widget->size());
      widget->render(&pixmap);
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • G Offline
        G Offline
        GunkutA
        wrote on last edited by
        #3

        @jsulm said in Taking screenshot of the dialog:

        QPixmap pixmap(widget->size());
        widget->render(&pixmap);

        Thanks for the reply, as I said I am beginner. Well I could not get what is widget in here represents to. I need to take the screenshot of the some part of the dialog which consists of multiple windgets ( I guess.). What should I put instead of widget? Also is there a way to choose the destination of the image will be saved?

        jsulmJ 1 Reply Last reply
        0
        • G GunkutA

          @jsulm said in Taking screenshot of the dialog:

          QPixmap pixmap(widget->size());
          widget->render(&pixmap);

          Thanks for the reply, as I said I am beginner. Well I could not get what is widget in here represents to. I need to take the screenshot of the some part of the dialog which consists of multiple windgets ( I guess.). What should I put instead of widget? Also is there a way to choose the destination of the image will be saved?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @GunkutA Replace widget with your dialog (a dialog is a widget also)

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          3
          • jsulmJ jsulm

            @GunkutA Replace widget with your dialog (a dialog is a widget also)

            G Offline
            G Offline
            GunkutA
            wrote on last edited by
            #5

            @jsulm Thank you

            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