【发布时间】:2021-06-01 16:46:42
【问题描述】:
我正在使用 PyQtWebEngine 制作一个网络浏览器,但是我将如何在其中提供隐身模式的功能。
【问题讨论】:
标签: python pyqt5 qtwebengine
我正在使用 PyQtWebEngine 制作一个网络浏览器,但是我将如何在其中提供隐身模式的功能。
【问题讨论】:
标签: python pyqt5 qtwebengine
答案在我在上一篇文章中已经指出的示例中:WebEngine Widgets Simple Browser Example。在Implementing Private Browsing 部分,他们指出提供与QWebEngineProfile::defaultProfile() 不同的QWebEngineProfile() 就足够了,因为后者默认由所有页面共享,这是在私密浏览中不搜索的内容。
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
class WebView(QtWebEngineWidgets.QWebEngineView):
def __init__(self, off_the_record=False, parent=None):
super().__init__(parent)
profile = (
QtWebEngineWidgets.QWebEngineProfile()
if off_the_record
else QtWebEngineWidgets.QWebEngineProfile.defaultProfile()
)
page = QtWebEngineWidgets.QWebEnginePage(profile)
self.setPage(page)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
view = WebView(off_the_record=True)
view.load(QtCore.QUrl("https://www.qt.io"))
view.show()
sys.exit(app.exec_())
【讨论】: