2

I can't figure out what is wrong. I'm using Qt 4.8.4 (clang, gcc). I want to print custom table which I construct using HTML. I found that I can't get words warp in table, and can't limit table width.

To understand that problem quicker, you can replay such behavior: create Qt project with MainWindow, write next code in its constructor:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QString tablesHtml("<table border=\"1\" width=\"200\">"
                   "<tr><td>"
                   "NOT LONG TEXT, 200px"
                   "</td></tr>"
                   "</table>"

                   "<table border=\"1\" width=\"300\">"
                   "<tr><td>"
                   "NOT LONG TEXT, 300px"
                   "</td></tr>"
                   "</table>"

                   "<table border=\"1\" width=\"300\">"
                   "<tr><td>"
                   "VEEERY LOOOONG TEEEEXT LONG LONG"
                   "VEEERY LOOOONG TEEEEXT LONG LONG"
                   "WHY NOT 300px, WHY?!"
                   "</td></tr>"
                   "</table>");
    doc.setHtml(tablesHtml);
    QPrinter prn;
    prn.setPageSize(QPrinter::A4);
    prn.setPageMargins(30, 20, 15, 20, QPrinter::Millimeter);
    QPrintPreviewDialog previewDialog(&prn);
    QObject::connect( &previewDialog, SIGNAL( paintRequested (QPrinter*) ),
                      this, SLOT ( onPrintRequested(QPrinter*) ));
    previewDialog.exec();
}

And add public slots: void onPrintRequested(QPrinter*p);:

void MainWindow::onPrintRequested(QPrinter *p)
{
    QPainter pnt(p);
    doc.drawContents(&pnt);
}

As a result I always got: Printing problem

EDIT:

  1. Here is information about how Qt handle html and css - Supported HTML Subset.
  2. Can this problem be solved omitting WebKit?
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
NG_
  • 6,895
  • 7
  • 45
  • 67
  • see this post http://stackoverflow.com/questions/1057574/html-td-wrap-text – 1337holiday Apr 14 '13 at 09:49
  • Nothing solves that problem (or I have not found yet). Think, this question is more Qt-specific. Here is info about how Qt handle html and css http://qt-project.org/doc/qt-4.8/richtext-html-subset.html. – NG_ Apr 14 '13 at 10:16

0 Answers0