0

It is possible to create screenshot of a Window content in Qt 5? E.g we have web browser and I want to create screen only of the page without chrome (menus window ...). Here is an example:

http://s7.postimg.org/5ekkmpdbd/question.png

Image above represent the feature which I want to implement in my Qt application.

Here is the example:

originalPixmap = QPixmap::grabWindow(QApplication::activeWindow()->winId());

there is a possibility to render only the content (web page) of the browser ang get the image?

QtBTD
  • 1
  • 1

1 Answers1

0

The way to deal with the chrome issue depends on what is your goal. The "chrome" you are referring to is a part of the web browser application that you're trying to interact with.

If you're doing this as a quick in-house hack, then you're free to hard code some offsets needed to trim the original pixmap so that the chrome is removed.

If you want something that can grab website screenshots and doesn't care on which browser is being used, you should be using WebKit bundled with Qt. Then you have full control over where the stuff is rendered.

If you want to grab screenshots from a user-provided browser, then one approach is to add an extension into the browser, and implement a server that can receive images from the extension running in the browser. The extension can be written in javascript presumably for everything out there but IE. It will be browser-specific, though.

Another approach is to check if the browser doesn't provide some other APIs that could be used for the purpose, without a need of writing an extension. For all I know, similar extensions should already exist. There surely are open source website testing frameworks out there that let you render a site in multiple browsers; they should provide this "grab from a browser" functionality.

Nitpick: In Qt 5 you should be using QScreen::grabWindow(), not the deprecated QPixmap::grabWindow(). I also hope that you're aware that if there are any windows in front of your window and obscuring it, they'll be grabbed. The grabbing is done from the screen, not directly from the window.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Thanks for reply. I exactly want to remove all stuff around the website (menus tabs etc). It should be just pure screen of webiste that I shown above. Unfortunatelly I can't use webkit so I have to do this QScreen::grabWindow() and look for childrens in the result? I see that some apps are doing some kind of detection (areas) and I don't now know ho to achieve this. – QtBTD Aug 30 '13 at 17:36
  • Is this for a product or an in-house hack? – Kuba hasn't forgotten Monica Aug 30 '13 at 17:47
  • The simplest way is to hard-code values. You can use very simple image "analysis" to figure out where does the website begin. Something as simple as looking at pixel values in one of the leftmost columns in `QImage` to figure out where the menu/toolbar color ends. – Kuba hasn't forgotten Monica Aug 30 '13 at 17:49