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. Capturing screen

Capturing screen

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.9k 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.
  • P Offline
    P Offline
    Panda9
    wrote on last edited by
    #1

    Hello,
    does QT5 deliver any high-level way to capture screen, like with PrintScreen?

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

      Hi,

      What do you mean by high level way ?
      With Qt5 you can take screenshots with help of "QScreen":http://qt-project.org/doc/qt-5/qscreen.html.
      Have a look at this "example":http://doc.qt.digia.com/qt-5.2/qtwidgets-desktop-screenshot-screenshot-cpp.html.
      Also this example would be in <QtDir>/Qt5.3.0/Examples/Qt-5.3/widgets/desktop/screenshot if you have installed Qt 5.3

      157

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Use QScreen and grabWindow function. It should satisfy your requirement

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Panda9
          wrote on last edited by
          #4

          Thank you. It's great for Linux, I don't have to use Imlib2 manually or something.
          But I have one doubt. I know that WId for whole screen in example is 0. But does this number it work outside X11?

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

            bq. But does this number it work outside X11?

            Didnt understand what you mean ?
            Above example works on Windows too.

            157

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Panda9
              wrote on last edited by
              #6

              @ if (screen)
              originalPixmap = screen->grabWindow(0);
              @
              http://qt-project.org/doc/qt-5/qscreen.html#grabWindow
              There is nothing about value of WId that should be used to capture whole screen, so I figured out that this can be environment-depended.
              In example as "WId" of whole screen is used 0, but why do I can be sure that it will work everywhere?
              Besides, where is WId defined/descripted?

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

                I too see there's no documentation for WId. But i think it could just be a Hexadecimal number. Well it works atleast on Linux and Windows platforms. Never tested on other platforms.
                But do you want to take screenshots of individual windows or the screens? Since as per docs,

                bq. The grabWindow() function grabs pixels from the screen, not from the window, i.e. if there is another window partially or entirely over the one you grab, you get pixels from the overlying window, too. The mouse cursor is generally not grabbed.

                So the screen which you want to capture should not be obstructed by other window or else its contents gets capture too.

                157

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Panda9
                  wrote on last edited by
                  #8

                  To be honest, I want to do almost exactly the same work in my code as does "scrot -s" command on Ubuntu. I could use scrot code which is on MIT license, but it isn't multiplatform (it work only with X11).

                  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