[Interest] Widget Screenshot Question

Jason Kretzer Jason at gocodigo.com
Fri Mar 6 20:00:16 CET 2015


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<mailto:Jason at gocodigo.com>
//-----------------------------//

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150306/511c989c/attachment.html>


More information about the Interest mailing list