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 create an in-application screen shot tool
Forum Updated to NodeBB v4.3 + New Features

How to create an in-application screen shot tool

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 1.3k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Tabula
    wrote on last edited by
    #1

    I would like to have a tool in my application to capture snapshots like with for example GreenShot.

    What I expect is to have an action that turns on this tool and with the mouse I can select a region that is found automatically. For example in a 2x2 viewport with images the option to select one of the views or all.

    How could I do that? How would I be able to catch mouse events without having handlers in the viewport itself?

    Regards,

    Marcel

    1 Reply Last reply
    0
    • Pradeep P NP Offline
      Pradeep P NP Offline
      Pradeep P N
      wrote on last edited by
      #2

      Hi,

      It can be done using QFileDialog::getSaveFileName()
      (For taking snapshot of your screen)

      Ex:

      (....)
      QString filename = QFileDialog::getSaveFileName(this, "Snapshot", ".png");

      filename = filename + ".png";
      (....)

      you can use any of the format in place of .png

      And use QPixmap for the data and saving the path.

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      1 Reply Last reply
      2
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        You can use QRubberBand to drag a area for which you want.
        TopLeft is the mouse press pos. MouseMove moves the bottom right corner of it and on mosue release you trigger your screen capture code.

        For this you capture the whole screen and just cut out the global rect of the QRubebrBand widget.

        Also see "this example":http://qt-project.org/doc/qt-4.8/desktop-screenshot.html.

        Or did i misunderstood something?
        Or do you just want to capture widgets inside your application?

        If so it's even simplier:
        use QApplication::widgetAt() and display for example a blinking border around it. On mousepress then use QPixmap::grabWidget()

        Edit: To filter mouse events you can install an event Filter on the QApplication itself.
        @qApp->installEventFilter(...)@

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GeorgePTVS
          wrote on last edited by
          #4

          FYI QPixmap::grabWidget() has been obsoleted in 5.4: Changes To Qt GUI

          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