How to create screenshot of web browser without chrome in Qt 5.1 - c++

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?

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.

Related

QWebView with YouTube

In my program, I have a QWebView that displays a YouTube video. The code I use has worked perfectly fine for me in the past, however one day I noticed it wasn't working anymore. I have Flash installed, and other websites (google) load just fine. Here is my code:
QNetworkProxyFactory::setUseSystemConfiguration(true);
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
ui->webView->load(QUrl("https://www.youtube.com/embed/abakM9O_Bos"));
ui->webView->setEnabled(true);
Can anyone explain why this used to work for me in the past but now it isn't? I tried http and https with no luck.
Things I would look into:
Do other video sites work? (Vimeo, for example)
Are you viewing the YouTube videos through flash, or HTML5?
Can you confirm that your web view is loading your flash plugin by going to one of the flash test pages?
Does it work with the Qt web browser example project?
If none of those point you in the right direction, I would definitely consider going to QtWebEngine. QtWebEngine is built using the Chromium platform, and is able to handle complex webpages really well. I've also noticed that QtWebEngine is significantly faster and more stable that the old QtWebKit based widgets. Plus, QtWebKit is no longer going to be updated, so if you're building a new application, it might be better to start with the newer system. Hopefully this helps!
Update
Just to summarize what has been stated in the comments:
This is likely an HTML5 issue, where QtWebKit doesn't have the H.264 codec built in.
As a result, you need to ship your application with the codecs you need. Specifically, I'd suggest ffmpeg (ffmpegsumo.dll), as this is what Chrome uses.

Qt Webview Google Maps Caching

I've created a Google maps widget that sub-classes QWebView. Basically, all of the google maps stuff is written in Javascript (using Google's Javascript API) and saved in an html file stored locally. Then, the widget just displays the html....and does some other stuff, but that's irrelevant.
The issue I am having is that the map tiles take significantly longer to load than if I open up the same html file in, say Chrome or Safari. Aren't Chrome and Safari based on the same WebKit that Qt uses?
Has anyone run into a similar situation? Is there a way to cache the map tiles so that it doesn't have to re-fetch them every time the display gets updated? Ideally, I would like to be able to cache them permanently so that my program can run off-line, but I know that is against Google's TOS. I will settle for being able to cache the tiles to speed up panning/zooming.
In searching around various forums, using QNetworkDiskCache has come up as a potential solution, but no one seems to be able to get that to work. I just can't seem to figure out why the same html/javascript runs significantly faster in Chrome and Safari than in QWebView
QNetworkDiskCache works fine with a Google map, with significant speed improvements compared to when it is not enabled. This should do the trick:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory(QCoreApplication::applicationDirPath() + "/cache");
manager->setCache(diskCache);
You then add the manager to your webView:
frame->page()->setNetworkAccessManager(manager);
frame->page()->settings()->setMaximumPagesInCache(10);
Then go on and load your html
frame->setHtml(...);

Controlling Internet Explorer in order to enter username/password

I was looking into trying to get my C++ application to do the following:
Open internet explorer
Open a webpage
Enter a name and password into specific forms in the webpage
Click the submit button on the webpage to open a new page
From my searching on the Internet it seems like using COM may make this possible, although I may be incorrect on that. I am doing my best to learn COM at the moment but some help would be great. I'm looking to do this without using MFC.
I have noticed this question which I kind of what I am looking for but I am having trouble understanding the suggested solutions. For example, I do not have a IWebBrowser2 option in my toolbox.
EDIT:
To make my question clearer, I had this task complete in a C# version by simply running a coded UI test but this will not work with C++. I am looking to open IE (not in the application itself), find the username and password forms, pass them string, then find the submit button on the page and click it.
This is very possible from c++. You will have to dive into the winapi to do some Keystroke stuff as well as window handling.
I'm not going to go into all of the code, but you have to do something like the following:
Start ie (if you give it a command line arg with the webpage, it will
open that page).
Make sure the ie window is focused (either just wait
if you want to keep it simple or use window's api to go through each
open HANDLE and find the window you want)
Use SendInput to send an Alt + D (to gain focus to the url bar, in firefox it will be a CTRL + L instead)
Use SendInput and javascript injection to modify the DOM as necessary
You can also submit the form (after everything is as you want it) using the above JS injection capability.
Yes, it is possible, but you have to embed a web browser control in your application, and it is not straightforward (I don't think you can automate DHTML in an external instance of Internet Explorer via COM).
I see that you don't want to use MFC, and this complicates even more the problem. Perhaps you can do it via ATL, I advise against even trying to do it without a framework.
If you could use MFC, then you could use a CDHtmlDialog form and access the underlying COM interfaces to automate the actions.
In the past, I developed an MFC application that used HTML as its user interface, but I used the CDHTMLView class that you can find here: http://www.codeproject.com/Articles/1783/Integrating-DHTML-into-MFC-Views
You can use this as an entry point for learning how to deal with DHTML events and how to play around with the IWebBrowser2 interface.
You should really take a look at WebDriver which is able to do exactly what you are describing. See (http://code.google.com/p/selenium/wiki/InternetExplorerDriverInternals) for more information about the InternetExplorerDriver internals. Even if you are not able to use the project directly, you can certainly browse the source to get a better idea of how what you want to do can be achieved.
What you want to do makes not much sense.
There are many APIs available to embed a browser view into your program. For example Qt offers this.
Then you can just do your HTTP POST request yourself and display the answer you get in your browser view.
That is a much cleaner solution.
Pro tip: Don't use Internet Explorer.

What possible web technology Google might have used for this 'Gideon Sundback doodle'

What possible web technology Google might have used for this Gideon Sundback doodle (see video)
http://www.youtube.com/watch?v=utijBRRmAJo&feature=relmfu
I am really curious. in a web browser, can we really do this much? I guess it is not flash, else i would not wonder. Any source code or similar samples available?
Guess it shows off how much we can extend in web technologies now.
A Canvas element <canvas> is used. All modern browsers supports HTML5 now - Firefox, chrome and Opera. Yes it is possible to do these with the browsers of today!
The zipper teeth are drawn onto the canvas from a png sprite file. The zipper slider also resides in that png image. The whole interactive animation is coded in the Javascript. The zipper peel effect is done using the arc() method of the context object, context being 2d in this case.
As soon as you click on the slider, it hides all the Dom elements - buttons and text input and all what you see is the canvas drawing. Since using the javascript code that is used, can't alone recreate the effect on the local html file. I think some external libraries are used. I am not sure how the google.listen() method works as its not defined. Check out the javascript here, in this thread, which is beautified javascript code, using the jsbeautifier.org

Browser Helper Object UI

I am a newbie working towards developing an IE extension that would appear as an overlay in certain webpages. I am getting started by creating a simple BHO in VS2008 (using C++), but I am wondering how UI may be incorporated within the project. Any ideas?
Just to give you an idea, I'm looking for overlays similar to what was developed by stickis
http://www.stickis.com/faq/
Thanks
You have two real options:
1> Inject your UI into the page as HTML.
2> Overlay your UI (using Windows graphics APIs) over top of the page.
Neither of these is super-simple, I'm afraid. Unfortunately, doing UI is usually the hardest part of building IE addons.
The key question is whether you need a BHO at all. Between context-menu extensions and IE8 Accelerators, you may find that you can let IE do all of the heavy lifting. See www.enhanceie.com/ie/dev.asp for more info.
Using CreateWIndowEx() was what I was looking for :)