5

I create HTML table in Qt:

QString css;
css = "<style type=\"text/css\">";
css += "table.tbl {border-width: 1px;border-style: solid;border-color: black;margin-top: 0px;margin-bottom: 0px;color: black;}";
css += "table.tbl td {padding: 3px;}";
css += "table.tbl th {padding: 3px;}";
css+="</style>";

QString text;
text="<table width=\"100%\" cellspacing=\"0\" class=\"tbl\">";
text+=("<tr><th>1</th><th colspan=\"2\">2</th><th>3</th><th></th></tr>");
text+=("<tr><td>1</td><td>2</td><td>3</td></tr>");
text+=("<tr><td colspan=\"2\">4</td><td>5</td><td>6</td></tr>");
text+=("<tr><td>7</td><td>8</td><td>9</td></tr>");
text+=("<tr><td>7</td><td>8</td><td>9</td></tr>");
text+=("<tr><td>7</td><td>8</td><td>9</td><td>8</td><td>9</td></tr>");
text+=("<tr><td>7</td><td>8</td><td>9</td></tr>");
text+=("<tr><td>7</td><td>8</td><td>9</td></tr>");
text+=("<tr><td>10</td><td>11</td><td>12</td></tr></table>");

And then I printed as a pdf document:

QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
printer.setPageMargins(10,10,10,50,QPrinter::Millimeter);
QTextDocument *document=new QTextDocument();
document->setHtml(css+text);
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (dlg->exec() != QDialog::Accepted)
    return;
document->print(&printer);

My table have single border but there is double line between third and fourth columns? How can I get rid of that? I can not use image tag because of my reputation but image of my table is here: https://i.stack.imgur.com/FC1Ck.jpg

Sorry for my poor English.

ekremk
  • 253
  • 3
  • 8
  • 18
  • Try making all of your table rows contain 5 cells. Most of your rows only have 3 cells defined. This may interfere with the rendering of the table. Add empty ``s to the rows with fewer than 5 cells. – glomad Jan 29 '13 at 17:51
  • I changed my code but nothing changed. Only double line is between second and third colums. – ekremk Jan 29 '13 at 18:05

1 Answers1

0

I understand this is an old question, but it has not been answered. I have been struggling with QT and HTML tables with QTextBrowser since last week, so this question created a great interest. In your code you have set equal padding '3px' for both td and th:

css += "table.tbl td {padding: 3px;}";
css += "table.tbl th {padding: 3px;}";

I believe this is where the problem lies. As 'th' has its own inbuilt padding, you need to reduce its custom padding by 1px. Replacing the above code with

css += "table.tbl td {padding: 3px;}";
css += "table.tbl th {padding: 2px;}";

should do the trick. This is what I achieved after modifying your code.

enter image description here

Gaurang
  • 67
  • 8