如何在不打开窗口的情况下使用QWebEngineView拍摄网页截图 [英] How to take webpage screenshots using QWebEngineView without opening window
问题描述
我正在寻找一种使用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屋!