My blog has been moved to ariya.ofilabs.com.

Thursday, October 20, 2005

Qt 4.1 Sports PDF Print, Backing Store, Highlighter

The upcoming Qt 4.1 will bring a new print engine: PDF. Yes, that's the Portable Document Format. A quick glance at the code reveals that it will be at PDF 1.4. We don't need to go to PostScript first and the use ps2pdf. All you need to create a PDF file from your application is:

  QPrinter printer( QPrinter::HighResolution );

  printer.setOutputFormat( QPrinter::PdfFormat );
  printer.setOutputFileName( "test.pdf" );
  
  QPainter painter;
  painter.begin(&printer);
  painter.setPen( Qt::red );
  painter.drawRect( printer.pageRect() );
  painter.drawLine( printer.pageRect().topRight(), 
    printer.pageRect().bottomLeft() );
  painter.end();

The above example draws red borders and a diagonal line in the paper. Note that somehow I still couldn't manage to output text. Either it is not supported (yet) or I made mistake.

Another neat feature is per-window backing store as it has been hinted by Matthias Ettrich. I do not know exactly what is backing store (perhaps some gurus can explain it?), but I supposed it will surpress flickers and give perceived smoothness in painting operations.

Last but not least, QSyntaxHighlighter for Qt 4's QTextEdit will make a debut. The lack of this in Qt 4.0 made implementing my favorite expressions highlighting difficult, but now I worry no more.

Qt 4.1 will be cool.

1 comment:

Ben Schleimer said...

A backing store is a double buffer.
Basically, every QT widget that is ever written and ever will be written uses a double buffer to eliminate flicker. So I guess, TT recognized this and just decided to make our lives easier. It has nothing to do with unresponsive applications and the paint events are still processed inorder but it does make it easier to build your own custom QT widgets.

Cheers,
Ben

PS. It is more expensive in terms of CPU cycles to force backing store on every widget but that's not really an issue anymore.