blob: 80f333323d1eb8ac9bc7efaf871b0aa33e1f45c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example webenginewidgets/stylesheetbrowser
\title WebEngine StyleSheet Browser Example
\ingroup webengine-widgetexamples
\brief Demonstrates how to inject CSS into web pages using user scripts.
\image stylesheetbrowser.png
\e {StyleSheet Browser} demonstrates how to use the \l{Qt WebEngine Widgets C++ Classes}
{Qt WebEngine C++ classes} to inject user stylesheets into web pages.
\include examples-run.qdocinc
\section1 Working With Stylesheets
We use JavaScript to create and append CSS elements to the documents.
After declaring the script source, QWebEnginePage::runJavaScript() can run it
immediately and apply newly created styles on the current content of the web view.
Encapsulating the script into a QWebEngineScript and adding it to the script collection
of QWebEnginePage makes its effect permanent.
\quotefromfile webenginewidgets/stylesheetbrowser/mainwindow.cpp
\skipto MainWindow::insertStyleSheet
\printuntil /^\}/
Removing stylesheets can be done similarly:
\quotefromfile webenginewidgets/stylesheetbrowser/mainwindow.cpp
\skipto MainWindow::removeStyleSheet
\printuntil /^\}/
\section1 Files and Attributions
The example uses icons from the Tango Icon Library:
\table
\row
\li \l{stylesheetbrowser-tango}{Tango Icon Library}
\li Public Domain
\endtable
*/
|