[Qt-interest] [webkit] QString to style sheet
Daniel Vérité
daniel.verite at gmail.com
Fri Jan 2 16:08:12 CET 2009
Hi,
This is a request for help or comments about getting a QString used as
a style sheet in webkit.
I need the user to choose a default font with a QFontDialog, and since
the QtWebkit API doesn't have a setFont(QFont), I'm converting QFont
properties to a CSS string in memory:
body { font-size: ...; font-family: ...; font-weight:...;
font-style:...; }
Now QWebPage accepts a user-supplied default style sheet, but it has to
be an URL, so I'm using a dummy URL: QUrl("style://internal.css") that
is caught by a custom network manager and for which the CSS string is
returned with a QNetworkReply-derived class. All this stuff to return
just a string but I haven't found a simpler way.
Ready-to-run minimal code is attached.
My question is: is that method correct? Because it appears to work for
me but not for another guy, despite us both using Qt-4.4.3 under linux,
so I'm wondering if there's something flawed in the concept or
implementation that would make it not guaranteed to work consistently.
By not working, I mean that the renderer appears to ignore the style
sheet.
Besides the attached code that uses a hardcoded CSS string, the
conversion from any QFont to CSS is pretty simple:
{
QString s="body {";
if (!font.family().isEmpty()) {
s.append("font-family:\"" + font.family() + "\";");
}
if (font.pointSize()>1) {
s.append(QString("font-size:%1 pt;").arg(font.pointSize()));
}
else if (font.pixelSize()>1) {
s.append(QString("font-size:%1 px;").arg(font.pixelSize()));
}
if (font.bold()) {
s.append("font-weight: bold;");
}
if (font.style()==QFont::StyleItalic) {
s.append("font-style: italic;");
}
else if (font.style()==QFont::StyleOblique) {
s.append("font-style: oblique;");
}
s.append("}\n");
}
Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: font-webkit.cpp
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090102/af429d99/attachment.pl
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: font-webkit.h
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090102/af429d99/attachment.h
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: font-webkit.pro
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090102/af429d99/attachment-0001.pl
More information about the Qt-interest-old
mailing list