PDA

View Full Version : QTextDocument + style CSS does not work



giusepped
15th June 2010, 14:05
I have an html string which stores some tables.
I would change the style of the tables by means of css style:

border: solid 1px

So, I used immediately after the constructor of QTextDocument



textdocument->setDefaultStyleSheet(cssTable())


where cssTable() returns



QString OutReport::cssTable()
{
QString a;
a = "<style type=\"text/css\">";
a += "table.sample {border-width: 10px;border-spacing: ;border-style: outset; border-color: gray; border-collapse: collapse; background-color: white; }";
a +=" table.sample th { border-width: 1px; padding: 1px; border-style: inset; border-color: gray; background-color: white; -moz-border-radius: ; }";
a += "table.sample td { border-width: 1px; padding: 1px; border-style: inset; border-color: gray; background-color: white; -moz-border-radius: ; }";
a+="</style>";
return a;
}


Then, when I wanna print a table in the text document,



totale = " <table class=\"sample\"><tbody><tr><td>"+ QObject::tr("Totale annuo") +"</td><td></td><td>" + t + "</tr>";
totale +="<tr><td>" + QObject::tr("Rendimento") + "</td><td></td><td>" + t2 +"</tr></table>";
...
textdocument->setHtml(totale);


But when I print with textdocument->drawContents(&p,printer->paperRect()) (p is a QPainter(printer)) nothing changes.
Why?

JohannesMunk
18th June 2010, 16:40
I couldn't get this to work, either. Just prepend your css-stuff to your html code. Works for me.

textdocument->setHtml(cssTable()+totale);

HIH

Johannes