[Interest] Widget Screenshot Question

Felix morack felixover at gmail.com
Sun Mar 8 11:35:54 CET 2015


I have the same problem...

Btw, there is a static method in Qthread to pause execution:
Qthreat::sleep().

2015-03-06 20:47 GMT+01:00 Jason Kretzer <Jason at gocodigo.com>:

> And to add a little more information, if I take out the “this->show()”, no
> image is created at all and this is put in the std out.
>
> plugins\win\PluginViewWin.cpp(875) : WebCore::PluginView::setNPWindowRect
>
> -Jason
>
> //------------------------------//
>    Jason R. Kretzer
>    Lead Application Developer
>    Jason at gocodigo.com
> //-----------------------------//
>
>
> From: "Jason R. Kretzer" <jason at gocodigo.com>
> To: "interest at qt-project.org" <interest at qt-project.org>
> Subject: [Interest] Widget Screenshot Question
>
> Hey everyone,
>
> I am trying to create a small app that opens a web view, waits a few
> seconds, and then takes a capture of the widget.  I don’t want it to open a
> window as I want to send it a bunch of URLs and have it generate a png of
> each url.  It works just fine if it is just a web site — for example,
> http://www.google.com
>
> Below is the code and below the code is what is currently happening.
>
> urlStr — goes to an url that is just an html file with a flash file
> embedded in it.
> savePathStr — where to save the png
> delay — how long to wait before taking the picture
> height/width — dimensions of the content
>
> void MainWindow::takeShot(QString urlStr, QString savePathStr, int delay,
> int height, int width)
> {
> QWebView *mWidget = new QWebView(this);
> mWidget->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,
> Qt::ScrollBarAlwaysOff);
> mWidget->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,
> Qt::ScrollBarAlwaysOff);
> mWidget->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
> mWidget->setGeometry(0, 0, width, height);
> mWidget->setUrl(QUrl(urlStr));
> mWidget->setWindowFlags(Qt::FramelessWindowHint);
> this->setWindowFlags(Qt::FramelessWindowHint);
> this->setGeometry(0,0,width,height);
> mWidget->load(QUrl(urlStr));
>
> this->show();
>
> //a delay to allow the flash to play through a bit
> QEventLoop delayloop;
> QTimer::singleShot(delay, &delayloop, SLOT(quit()));
> delayloop.exec();
>
> QRect rectangle = mWidget->geometry();
> QPixmap pixmap(rectangle.size());
>
> //I have tried this to no avail
> //pixmap = mWidget->grab(rectangle);
>
> //I have tried this also to no avail
> Pixmap = this->grab(rectangle);
>
> //I have tried this also to no avail
> mWidget->render(&pixmap, QPoint(), QRegion(rectangle));
>
> pixmap.save(savePathStr);
> …….//REST OF THE CODE OMITTED
> }
>
> What happens is that the image is created.  However, there is a big blank
> spot where the embedded flash is supposed to be.
>
> Has anyone else run into this or have any other pointers?
>
> I am using Qt 5.3.1 andWin7.
>
> -Jason
>
> //------------------------------//
>    Jason R. Kretzer
>    Lead Application Developer
>    Jason at gocodigo.com
> //-----------------------------//
>
> ------------------------------
>
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2015.0.5645 / Virus Database: 4299/9221 - Release Date: 03/03/15
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150308/1469a7a1/attachment.html>


More information about the Interest mailing list