Hi.
Down is my print function. As advised by the answers to my previous question I am using qtextdocument with html to print my text.
I have made some progress.
I have a query to database to grab some text and create a few paragraphs to print.
Until here its ok, but if my blocks of text are several and if they are large, its natural that I need more pages to print.
I know that I can use printer->newPage() to create a new printing page. But the text will be all written to the first page and INCOMPLETE if larger than the page!
It should go to the next page...
How can I solve this problem?
Can someone point me to the right direction please?
Thanks a lot...
daniel
void Janela:rint( QPrinter* printer )
{
// create painter for drawing print page
QPainter painter( printer );
int w = printer->pageRect().width();
int h = printer->pageRect().height();
QRect page( 0, 0, w, h );
// create a font appropriate to page size
QFont font = painter.font();
font.setPixelSize( (w+h) / 120 );
QTextDocument doc;
QTextCursor cursor(&doc);
doc.setDefaultFont(font);
doc.setHtml( "<html>"
"<body>"
"<h2>bla bla bla bla bla</h2>");
cursor.insertBlock();
cursor.insertBlock();
cursor.insertHtml("<h3>bla bla</h3>");
cursor.insertBlock();
db.setDatabaseName(NomeBD);
db.open();
QSqlQuery query;
query.exec("SELECT * FROM table WHERE date >= #10-29-2010#");
while (query.next())
{
cursor.insertHtml("<h4>" + query.value(0).toString().right(8) + " - " + query.value(1).toString() + " - " + query.value(2).toString() + ":</h4>");
cursor.insertBlock();
cursor.insertHtml("<p>" + query.value(3).toString() + "</p>");
cursor.insertBlock();
}
db.close();
cursor.insertHtml("</body>");
cursor.insertHtml("</html>");
doc.setTextWidth(page.width());
doc.setDocumentMargin(w/10);
doc.drawContents(&painter, page);
}
Bookmarks