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. How to capture current main window screen shot on button click, and set that captured image as modal window background in QT?
Forum Updated to NodeBB v4.3 + New Features

How to capture current main window screen shot on button click, and set that captured image as modal window background in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 928 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.
  • N Offline
    N Offline
    NageswaRao
    wrote on last edited by
    #1

    Hi Team, my requirement is capturing the current running main window screenshot when we clicked some button and opening that captured screenshot in the modal window or modal less window. In that modal window, I have to implement some Zoom in/out functionality. Is it possible to do that? Any suggestions, Thank you in advance.

    jsulmJ 1 Reply Last reply
    0
    • N NageswaRao

      Hi Team, my requirement is capturing the current running main window screenshot when we clicked some button and opening that captured screenshot in the modal window or modal less window. In that modal window, I have to implement some Zoom in/out functionality. Is it possible to do that? Any suggestions, Thank you in advance.

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

      @NageswaRao See https://forum.qt.io/topic/90459/taking-screenshot-of-a-specific-focused-window/2

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

      1 Reply Last reply
      1
      • N Offline
        N Offline
        NageswaRao
        wrote on last edited by
        #3

        Thank you Jsulm. I'll try this approach.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          NageswaRao
          wrote on last edited by
          #4

          Hi Jsulm, I'm having some train tracks and text related signals. This code is worked for getting the screenshot and text on that. I'm not able to capture train tracks in that screenshot. any suggestion.

          jsulmJ 1 Reply Last reply
          0
          • N NageswaRao

            Hi Jsulm, I'm having some train tracks and text related signals. This code is worked for getting the screenshot and text on that. I'm not able to capture train tracks in that screenshot. any suggestion.

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

            @NageswaRao What are "train tracks" and what code do you mean?

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

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NageswaRao
              wrote on last edited by
              #6

              Sorry, Jsulm. I'll explain it. I'm having a desktop sample application of QT. After login to that application, we will land on to the dashboard. There we generally display one train track(i.e in the form of some railway train track using lines) and several stations information(in some text) in that dashboard. Now what I'm doing is, I added one button on the dashboard. after clicking that button I'm able to get a dialog box. In that dialog box, I'm getting a screenshot also with the following code.

              auto active_window = qApp->activeWindow();
              if (active_window) //could be null if your app doesn't have focus
              {
                  QPixmap pixmap(active_window->size());
                  active_window->render(&pixmap);
                  ui->label_pic->setPixmap(pixmap);
              }
              

              In that screenshot, I'm not getting railway train tracks related lines.
              Is there any suggestion to get that every thing when we capture the screen shot?

              jsulmJ 1 Reply Last reply
              0
              • N NageswaRao

                Sorry, Jsulm. I'll explain it. I'm having a desktop sample application of QT. After login to that application, we will land on to the dashboard. There we generally display one train track(i.e in the form of some railway train track using lines) and several stations information(in some text) in that dashboard. Now what I'm doing is, I added one button on the dashboard. after clicking that button I'm able to get a dialog box. In that dialog box, I'm getting a screenshot also with the following code.

                auto active_window = qApp->activeWindow();
                if (active_window) //could be null if your app doesn't have focus
                {
                    QPixmap pixmap(active_window->size());
                    active_window->render(&pixmap);
                    ui->label_pic->setPixmap(pixmap);
                }
                

                In that screenshot, I'm not getting railway train tracks related lines.
                Is there any suggestion to get that every thing when we capture the screen shot?

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

                @NageswaRao said in How to capture current main window screen shot on button click, and set that captured image as modal window background in QT?:

                There we generally display one train track

                How? Do you paint it in the paintEvent?

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

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  NageswaRao
                  wrote on last edited by
                  #8

                  Hi Jsulm, thank you. OpenGL is used in sample application. so because of different layers on-screen, able to capture one layer. but with the below code, we achieved what I needed. thank you.

                      QRect crop_rect(500, 500, 250, 250);
                      QImage desk = qApp->screens().at(0)->grabWindow(
                      QDesktopWidget().winId(),
                      crop_rect.left(),
                      crop_rect.top(),
                      crop_rect.width(),
                      crop_rect.height()).toImage();
                      ui->label_pic->show();
                      ui->label_pic->setPixmap(QPixmap::fromImage(desk));
                      ui->label_pic->resize(200,200);
                      ui->label_pic->setStyleSheet("border:5px solid grey");
                  
                  1 Reply Last reply
                  1

                  • Login

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