PDA

View Full Version : CSS Issue with QTextEdit



schall_l
8th July 2009, 08:35
Hello,

I have followed the document from http://doc.qtsoftware.com/4.5/richtext-html-subset.html to set some css style when declaring an html string that will later on be used in a QTextEdit widget.

Some of the css style are working, while others have not effect.
In my example:
background is working
color is working
align is NOT working
font-size is NOT working

Did I miss something?


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString html_sequence = QString(" \
<html> \
<head> \
<style type=text/css> \
body { background: #ffffff; color: black; } \
.title { background: #f0f0f0; align: center; } \
.subtitle { font-size: 8px; color: red;} \
.small-subtitle { font-size: 6px; color: blue; } \
</style> \
</head> \
\
<body> \
<h1 class=title>Title without subtitle<br /></h1> \
<h1 class=title>Title with subtitle<br /><span class=subtitle>This is the subtitle</span></h1> \
<h1 class=title>Title with small subtitle<br /><span class=small-subtitle>This is the small subtitle</span></h1> \
</body> \
</html> \
");

QTextEdit test(html_sequence);
test.show();
return app.exec();
}

nish
8th July 2009, 08:37
can u give the string in one line?

wysota
8th July 2009, 08:39
Does it change anything if you set the attributes with style="..." attribute to specified tags instead of using the <style> tag?

schall_l
8th July 2009, 08:41
MrDeath, I used the backslahes in order to make the html string more readable.
Wasota, I will try your suggestion, but why is it working for some attributes and why is it not working for some other ?

schall_l
8th July 2009, 09:06
Could this simply be a bug in QT4.5 ?

wysota
8th July 2009, 09:37
Could this simply be a bug in QT4.5 ?

No. It works fine for me.

<p style="font-size:36pt;">BLA</p>
<p align="center">XYZ</p>

schall_l
8th July 2009, 09:56
why are:

.title { background: #f0f0f0; text-decoration: underline; }
.title { color: red; }
.title { font-size:large;}

working and

.title { align: center; }
.title { font-size:8px; }

not working ?

wysota
8th July 2009, 10:54
Try pt instead of px.

schall_l
8th July 2009, 12:37
No no no, I've tried this before.

I am still thinking that this could be a bug in Qt as some of the attributes from http://doc.qtsoftware.com/4.5/richtext-html-subset.html will work and some will not work.

wysota
8th July 2009, 17:58
Yes, it's always easiest to blame someone else but still using pt instead of px did work for me :)

schall_l
9th July 2009, 08:04
This is the code using pt instead of px and the attached screenshot.
As you can see some of the attributes are interpreted correctly, some not.


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString html_sequence = QString(" \
<html> \
<head> \
<style type=text/css> \
body { background: #ffffff; color: black; } \
.title { background: #f0f0f0; align: center; } \
.subtitle { font-size: 8pt; color: red;} \
.small-subtitle { font-size: 6pt; color: blue; } \
</style> \
</head> \
\
<body> \
<h1 class=title>Title without subtitle<br></h1> \
<h1 class=title>Title with subtitle<br><span class=subtitle>This is the subtitle</span></h1> \
<h1 class=title>Title with small subtitle<br><span class=small-subtitle>This is the small subtitle</span></h1> \
</body> \
</html> \
");

QTextEdit test(html_sequence);
test.show();
return app.exec();
}

schall_l
9th July 2009, 08:07
Could it be that there is some priority relevant issues ?
Could possibly <h1> be evaluated with a higher priority then the font-size attribute from subtitle and small-subtitle ?
What's about the priority of align: center ?

wysota
9th July 2009, 08:35
<html>
<head>
<style type=text/css>
body { background: #ffffff; color: black; }
.title { background: #f0f0f0; }
.subtitle { font: 8pt; color: red;}
.small-subtitle { font: 6pt; color: blue; }
</style>
</head>

<body>
<h1 align="center" class=title>Title without subtitle<br></h1>
<h1 align="center" class=title>Title with subtitle<br><span class=subtitle>This is the subtitle</span></h1>
<h1 align="center" class=title>Title with small subtitle<br><span class=small-subtitle>This is the small subtitle</span></h1>
</body>

I can't get "font-size" to work with pt or px, it works otherwise.

schall_l
9th July 2009, 15:50
Just for your information, I have asked the same question to Nokia.
They have reported this as a bug in Qt with the task ID 257767.