PDA

View Full Version : QTextDocument: borders style for particular cells



qks1
25th March 2013, 13:42
Hi! First of all - sorry for my English, I'm trying to do my best.

I want to make the report (and print it) with quite complex table. Last row of my table must be painted in part, i.e. part of cells shouldn't be painted. Something like that:

8845

In HTML terms it looks like that (very garbage code, just explain my idea):


<table cellspacing=0 style="border-collapse: collapse">
<tr><td style='border: 1px solid black'>1</td>
<td style='border: 1px solid black'>2</td>
<td style='border: 1px solid black'>3</td></tr>
<tr><td style='border: 1px solid black'>One</td>
<td style='border: 1px solid black'>Two</td>
<td style='border: 1px solid black'>Three</td></tr>
<tr><td style='border-width: 1 0 0; border-style: solid; border-color: black'></td>
<td style='border-width: 1 0 0; border-style: solid; border-color: black'></td>
<td style='border: 1px solid black'>Finish</td></tr>
</table>

I'm using QTextDocument for my task. But neither setHtml() or QTextCursor (rather QTextTable) doesn't support styles for particular tables, only for the whole table! My attemps (using html, QTextCursor gives about the same result):
1) if set border style to the whole table, we get proper borders (a bit of thick, but that's other question):

QString html = "<html><body>";
html += "<table cellspacing=0 cellpadding = 2 style='border-width: 1px; border-style: solid; border-color: #000000'>";
html += "<tr>";
html += "<td>1</td>";
html += "<td>2</td>";
html += "<td>3</td>";
html += "</tr>";
html += "<tr>";
html += "<td>One</td>";
html += "<td>Two</td>";
html += "<td>Three</td>";
html += "</tr>";
html += "<tr>";
html += "<td></td>";
html += "<td></td>";
html += "<td>Finish</td>";
html += "</tr>";
html += "</table></body></html>";

page->setHtml(html);
8846

2) If try to make the same as with HTML (i.e. set border style for every cell), we get no borders at all.

QString html = "<html><body>";
html += "<table cellspacing=0 cellpadding=2'>";
html += "<tr>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>1</td>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>2</td>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>3</td>";
html += "</tr>";
html += "<tr>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>One</td>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Two</td>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Three</td>";
html += "</tr>";
html += "<tr>";
html += "<td style='border-style: none;'></td>";
html += "<td style='border-style: none;'></td>";
html += "<td style='border-width: 1px; border-style: solid; border-color: #000000'>Finish</td>";
html += "</tr>";
html += "</table></body></html>";

page->setHtml(html);
8847

But I need the table at the beginning of my post. Any suggestions? Only crazy option comes to mint: stupidly draw each line with QPainter...

jesse_mark
25th March 2013, 17:26
Only crazy option comes to mint: stupidly draw each line with QPainter...

here is another crazy idea draw a white rect on the area you do want to show :P

qks1
26th March 2013, 09:48
here is another crazy idea draw a white rect on the area you do want to show :P

Yes, an option too :) On the another forum, someone suggested me to use QWebView. I think that's not bad idea, but I have a print problems. But that is different chapter, so I'll better create one more topic...