PDA

View Full Version : QTextEdit html rendering issues



haldrik
14th July 2012, 07:02
Hi, i'm trying to render a html file, is a report from a query, with this code:


void SalesForm::renderProposal()
{
QString fileName = QDir::currentPath() + "/templates/proposal_template.html";
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, trUtf8("Error Abriendo Plantilla"),
trUtf8("No se puedo abrir '%1'").arg(fileName));
}

QTextStream stream(&file);
QString htmlString;
htmlString = stream.readAll();
QString textEditString = htmlString.arg(propsData.at(0).at(0)).arg(propsDat a.at(3).at(0)).arg(propsData.at(16).at(0));
propOutTextEdit->setHtml(textEditString);
}
}

The file loads fine, but the QTextEdit don't render very well the html file, I took a screenshot where the file is loaded
on Google Chrome and QTextEdit twice.

8013

html code is shown here:
http://pastebin.ca/2170961

I'm not trying to compare Google Chrome with QTextEdit, but the html file is very simple and is made with kompozer.

Thanks.

ChrisW67
14th July 2012, 09:04
QTextEdit only supports a subset of HTML that does not specifically mention width styles on table elements. If you want a fully fledged HTML/CSS (read only) experience then use WebKit.

haldrik
14th July 2012, 18:13
Thanks,

But if you look the html code you will see that I don't use CSS or other not supported html subset, for
example, documentation says:

table Table Supports the following attributes: border, bgcolor (Qt color names or #RRGGBB), cellspacing, cellpadding, width (absolute or relative), and height.

My tabable is defined with:


<table style="text-align: left; width: 300px; height: 58px;" border="1" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top; width: 180px;">FORMA DE PAGO<br>
</td>
<td style="vertical-align: top; width: 80px;">%37<br>
</td>
</tr>
<tr>
<td style="vertical-align: top;">VALIDEZ DE LA OFERTA<br>
</td>
<td style="vertical-align: top;">%38<br>
</td>
</tr>
</tbody>
</table>


And it says too that supports align, but if you see this line, I used supported align set:


<div style="text-align: right; font-weight: bold;"><big><big>PROPUESTA COMERCIAL</big></big><br>
</div>

But in QTextEdit text is shown on the left.
Thanks again.

haldrik
17th July 2012, 00:53
I just used QWebView, including <QtWebKit/QWebView> and the webkit module on my .pro file too.

wysota
17th July 2012, 01:15
But if you look the html code you will see that I don't use CSS or other not supported html subset
This:
style="text-align: left; width: 300px; height: 58px;"
... is CSS.

haldrik
17th July 2012, 03:25
Ohh, ok, thanks. :o :o

ChrisW67
17th July 2012, 07:35
And it says too that supports align, but if you see this line, I used supported align set:


<div style="text-align: right; font-weight: bold;"><big><big>PROPUESTA COMERCIAL</big></big><br>
</div>


Just to reinforce this, this a is "div" element with a "style" attribute containing CSS properties. The supported attributes for this element are "align" and "dir". Even if "style" were supported here, the allowed CSS subset does not include "text-align".