Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, August 2006
Printing rich text


Message 1 in thread

Hi all!

I think, for the most of you, my question is too simple, so I want to 
appologise.
But I don't know how to start ...

What I want to do, is to include somewhere in my printout a QString which 
contains a rich text.

I draw some other texts, images, tables on the page, and then I want to 
start printing the rich text I get from a QString.
So I have the position on page, where I should start including the text.
The text may be long enough to continue on the next pages.

How could it be possible to build such blocks of text according to my pages 
limits, and then have these blocks printed?

I mention that I use Qt 4.1 and MS VS7.

Thanks in advance for your help!

Andi


--
 [ signature omitted ] 

Message 2 in thread

> What I want to do, is to include somewhere in my printout a QString which
> contains a rich text.

There is a very easy way with Qt 4 to print rich text.  Just do this:

    // Ask the user about printer settings
    QPrinter printer;
    QPrintDialog dialog( &printer, someWindowHere );
    if ( dialog.exec() == QDialog::Accepted ) {
        QString myRichText;
        // fill that string with your data using this subset of HTML
        // http://doc.trolltech.com/4.1/richtext-html-subset.html
        QTextDocument doc;
        doc.setHtml( myRichText );
        doc.print( &printer );
    }

Nathan


--
 [ signature omitted ]