Reputation: 596
I'm struggling with a QT5 problem. I'm trying to build (and then paint on a QPainter
object) an HTML table. This is my code:
QTextDocument td;
QString table_style= QString("<style type=\"text/css\">"
".tg { table-layout: fixed; width: 200px; }"
".tg td{padding-bottom: 5px;border-style:solid;border-width:0px;}"
".tg .tg-3x1q{color: rgba(255, 255, 255, 0.5); text-align:right}"
".tg .tg-6bqv{color: rgba(255, 255, 255, 0.5); padding-left: 5px;}"
"</style>");
QString table_html = QString(" <table width=\"500px\" class=\"tg\">"
"<tr>"
"<td class=\"tg-3x1q\" width=\"150px\">1</td>"
"<td class=\"tg-6bqv\" width=\"150px\"><sup>th</sup></td>"
"</tr>"
"<tr>"
"<td class=\"tg-3x1q\" width=\"150px\">2</td>"
"<td class=\"tg-6bqv\" width=\"150px\"><sup>rpm</sup></td>"
"</tr>"
"<tr>"
"<td class=\"tg-3x1q\" width=\"150px\">3</td>"
"<td class=\"tg-6bqv\" width=\"150px\"><sup>km/h</sup></td>"
"</tr>"
"</table>");
td.setDefaultStyleSheet(table_style);
td.setHtml(table_html);
td.drawContents(painter);
The table is correctly showed in the painter BUT has no fixed column width. To achieve that result I've tried almost everything:
table-layout: fixed
but from QT's docs is not supported (but width is!)width
with or without double quotes, relative or absolutelydiv
with a fixed widthTried (following this question http://www.qtcentre.org/threads/31661-QTextDocument-style-CSS-does-not-work) to add the style with the body. Like this
td.setHtml(table_style + table_html);
None of these ways worked. Moreover, if I try to add some spaces to pad the row they were trimmed out once the table was painted. I've also read that I could use the WebView
to achieve the result but it's too slow.
I'm stuck, I hope that someone could help me to figure it out.
Upvotes: 2
Views: 4683
Reputation: 98435
QTextDocument
is not a renderer of any standard HTML. It implements a slightly incompatible HTML- and CSS-subset. For example, the px
suffix is not supported. All dimensions are either in pixels (without a suffix) or in percent (with %
suffix). You might wish to try the widths without the px
suffix.
You can only rely on QTextDocument
-related documentation of the markup it implements, not on general HTML/CSS documentation.
Upvotes: 7