Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3c2eff3d authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Inject custom style sheet with system colors

WebView follows the color of the application but text does not leading to
black text on dark gray background.

BUG: 360214

Differential Revision: https://phabricator.kde.org/D6402
parent 24c0b5fd
......@@ -72,6 +72,22 @@ class ScriptingHtmlDialog : public QDialog {
m_webView.page()->setNetworkAccessManager(NULL); //Disable talking to remote servers
m_webView.page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAsNeeded);
m_webView.page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAsNeeded);
// inject a style sheet that follows system colors, otherwise we might end up with black text on dark gray background
const QString styleSheet = QStringLiteral(
"body { background: %1; color: %2; }" \
"a { color: %3; }" \
"a:visited { color: %4; } "
).arg(palette().background().color().name(),
palette().text().color().name(),
palette().link().color().name(),
palette().linkVisited().color().name());
// you can only provide a user style sheet url, so we turn it into a data url here
const QUrl dataUrl(QStringLiteral("data:text/css;charset=utf-8;base64,") + QString::fromLatin1(styleSheet.toUtf8().toBase64()));
m_webView.settings()->setUserStyleSheetUrl(dataUrl);
#endif
}
#if HAVE_QTWEBKITWIDGETS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment