[Qt-interest] QWebView does not load external stylesheet

Bart van Deenen bvandeenen at infologic.nl
Wed Apr 1 12:39:03 CEST 2009


Hi all

QWebView->setHtml seems to ignore links to external stylesheets, or I'm doing 
something wrong.



At first I didn't add the working directory argument to setHtml, but that had 
the same results.

What can I do to make the link to the external css work? I'm using QT4.5 on 
Linux.

Here's my testcase



======= webview.css ====== (in the same directory as the application)
body { border: thin solid black; font-weight: bold }



====== main.cpp =======
#include <QApplication>
#include <QWebView>
#include <QTextStream>
#include <QDebug>
#include <QDir>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWebView wv;
    QString mypage;
    QTextStream p(&mypage);
    p << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"      
\"http://www.w3.org/TR/html4/strict.dtd\">\n ";
    p <<"<html><head>\n<link rel='stylesheet' type='text/css'";
    p  << " href='webview.css' />\n";
    p << "<style type='text/css'>body { color:red } </style>";
    p << "<body>hello</body></html>\n";
   qDebug() << mypage;
    wv.setHtml(mypage, QUrl::fromLocalFile(QDir::currentPath()));
    wv.show();
    return a.exec();
}

====  debugging output ======
"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"      
"http://www.w3.org/TR/html4/strict.dtd">
 <html><head>
<link rel='stylesheet' type='text/css' href='webview.css' />
<style type='text/css'>body { color:red } </style><body>hello</body></html>
" 
===== project file ======
QT       += webkit
QT       += gui
TARGET = webkit-external-css
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090401/7731a4cf/attachment.html 


More information about the Qt-interest-old mailing list