int main( int argc, char **argv )
{
QApplication app( argc, argv );
QPixmap pixmap( 200, 330 );
pixmap.fill( Qt::white );
QPainter painter( &pixmap );
painter.setPen( Qt::black );
QPoint point = QPoint( 10, 20 );
painter.drawText( point, "You can draw text from a point..." );
painter.drawLine( point+QPoint(-5, 0), point+QPoint(5, 0) );
painter.drawLine( point+QPoint(0, -5), point+QPoint(0, 5) );
QRect rect = QRect(10, 30, 180, 20);
painter.drawText( rect, Qt::AlignCenter,
"...or you can draw it inside a rectangle." );
painter.drawRect( rect );
rect.translate( 0, 30 );
QFont font = QApplication::font();
font.setPixelSize( rect.height() );
painter.setFont( font );
painter.drawText( rect, Qt::AlignRight, "Right." );
painter.drawText( rect, Qt::AlignLeft, "Left." );
painter.drawRect( rect );
rect.translate( 0, rect.height()+10 );
rect.setHeight( QFontMetrics( font ).height() );
painter.drawText( rect, Qt::AlignRight, "Right." );
painter.drawText( rect, Qt::AlignLeft, "Left." );
painter.drawRect( rect );
QTextDocument doc;
doc.setHtml( "A QTextDocument can be used to present formatted text "
"in a nice way.
"
"It can be formatted "
"in different ways.
"
"The text can be really long and contain many "
"paragraphs. It is properly wrapped and such...
" );
rect.translate( 0, rect.height()+10 );
rect.setHeight( 160 );
doc.setTextWidth( rect.width() );
painter.save();
painter.translate( rect.topLeft() );
doc.drawContents( &painter, rect.translated( -rect.topLeft() ) );
painter.restore();
painter.drawRect( rect );
rect.translate( 0, 160 );
rect.setHeight( doc.size().height()-160 );
painter.setBrush( Qt::gray );
painter.drawRect( rect );
pixmap.save( "text.png" );
return 0;
}