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:
EDIT:
- Here is information about how Qt handle html and css - Supported HTML Subset.
- Can this problem be solved omitting WebKit?