是的,这是可能的,
Scene = std::make_unique<QGraphicsScene>();
HiddenView = std::make_unique<QGraphicsView>(mScene.get());
WebView = std::make_unique<QWebEngineView>();
Scene->addWidget(mWebView.get());
WebView->resize(size); //any QSize you like
WebView->load(url); // give your url here
mWebView->show(); //this doesn't actually show, just enables you to render offscreen, see below
ImageData = QImage(size, QImage::Format_ARGB32);
connect(mWebView.get(), &QWebEngineView::loadFinished, this, &ClassA::onViewLoaded);
然后,在 onViewLoaded 中,我们调用 update() 方法定期渲染。请注意,“this”是 ClassA 的对象。
void ClassA::onViewLoaded(){
Timer = std::make_unique<QTimer>();
connect(mTimer.get(), &QTimer::timeout, , &SpaOffscreenRender::update);
mTimer->start(30); //every 30 miliseconds
}
最后你像这样渲染:
void ClassA::update()
{
QPainter painter(&ImageData);
WebView->page()->view()->render(&painter);
painter.end();
}
ImageData 有你想要的:)