folibis
27th November 2013, 02:17
I use QWebView as template editor in my app.
Structure of my project:
MyProject/
app.exe
Templates/
style.css
template.html
This is simplified HTML code of template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<p>Some content</p>
</body>
</html>
in same directory I have style.css:
html,body {
font-family:Tahoma;
}
But QWebView ignores my styles. I guess it just can't load it.
Code for content loading:
QFile file(QApplication::applicationDirPath() + "/Templates/template.html");
QUrl url(QApplication::applicationDirPath() + "/Templates");
ui->textEdit->setHtml(file.readAll(),url);
I tried
ui->textEdit->settings()->setUserStyleSheetUrl(url);
and
QUrl url("file://" + QApplication::applicationDirPath() + "/Templates");
but nothing helps.
So how can I load local css file to QWebView?
Structure of my project:
MyProject/
app.exe
Templates/
style.css
template.html
This is simplified HTML code of template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<p>Some content</p>
</body>
</html>
in same directory I have style.css:
html,body {
font-family:Tahoma;
}
But QWebView ignores my styles. I guess it just can't load it.
Code for content loading:
QFile file(QApplication::applicationDirPath() + "/Templates/template.html");
QUrl url(QApplication::applicationDirPath() + "/Templates");
ui->textEdit->setHtml(file.readAll(),url);
I tried
ui->textEdit->settings()->setUserStyleSheetUrl(url);
and
QUrl url("file://" + QApplication::applicationDirPath() + "/Templates");
but nothing helps.
So how can I load local css file to QWebView?