如何在不打开窗口的情况下使用QWebEngineView拍摄网页截图 [英] How to take webpage screenshots using QWebEngineView without opening window

查看:560
本文介绍了如何在不打开窗口的情况下使用QWebEngineView拍摄网页截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用QWebEngineView拍摄网站截图的方法.主要目标是开发在后台运行的无头屏幕捕获应用程序.

我设法获得了一个最小的工作示例(请参见).但是,这些示例要求通过调用QWebEngineView::show()QWebEngineView::showMinimized()或什至QWebEngineView::setVisible(true)来使QWebEngineView小部件可见,以便能够截取网站的屏幕截图.由于这会导致打开一系列窗口,因此该解决方案并不完美.

有没有人知道使用QWebEngineView来截取网站屏幕快照而不打开窗口的方法?

解决方案

解决方案非常简单:通过调用QWidget::setAttribute(Qt::WA_DontShowOnScreen)设置Qt::WA_DontShowOnScreen属性,将QWebEngineView小部件配置为不显示在屏幕上.

http://doc.qt.io/qt-5/qt.html#WidgetAttribute-枚举

I'm looking for a way to take website screenshots with QWebEngineView. The main goal is to develop a headless screencapture application that runs in the background.

I've managed to get a minimal working example to work (see this for example). However, these examples require that the QWebEngineView widget is made visible, either with calls to QWebEngineView::show(), QWebEngineView::showMinimized() or even QWebEngineView::setVisible(true), to be able to take a screen capture of a website. As this results in opening a series of windows, this solution is less than perfect.

Does anyone know of a way to use QWebEngineView to take screenshots of websites without having windows popping open?

解决方案

The solution is rather easy: configure the QWebEngineView widget to not show onscreen by setting the Qt::WA_DontShowOnScreen attribute through a call to QWidget::setAttribute(Qt::WA_DontShowOnScreen).

http://doc.qt.io/qt-5/qt.html#WidgetAttribute-enum

这篇关于如何在不打开窗口的情况下使用QWebEngineView拍摄网页截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆