Using Chrome Flags With Qtwebengine (pyqt5)
For the development of my PyQt5 browser project, I read here that by passing Chrome flags as application arguments, they will automatically be passed onto the QtWebEngineProcess.ex
Solution 1:
To set the chromium flags can be done using the following methods(See the docs):
Pass as arguments to QApplication:
args = ["--foo-arg=foo-value", "--bar-arg=bar-value"] app = QtWidgets.QApplication(args) # or # app = QtWidgets.QApplication(sys.argv + args)
Set it through the environment variable
QTWEBENGINE_CHROMIUM_FLAGS
:import os os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--foo-arg=foo-value --bar-arg=bar-value" app = QtWidgets.QApplication(sys.argv)
And therefore your attempt is correct but the problem seems to be that not all chromium flags are supported by Qt WebEngine and that seems to be the case for --enable-force-dark
. Searching the net I found this post that provides an alternative: --blink-settings=darkMode=4,darkModeImagePolicy=2
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
if __name__ == "__main__":
import os
import sys
os.environ[
"QTWEBENGINE_CHROMIUM_FLAGS"
] = "--blink-settings=darkMode=4,darkModeImagePolicy=2"
app = QtWidgets.QApplication(sys.argv)
# or# args = sys.argv + ["--blink-settings=darkMode=4,darkModeImagePolicy=2"]# app = QtWidgets.QApplication(sys.argv + args)
view = QtWebEngineWidgets.QWebEngineView()
view.load(QtCore.QUrl("https://www.google.com"))
view.show()
sys.exit(app.exec_())
Post a Comment for "Using Chrome Flags With Qtwebengine (pyqt5)"