My blog has been moved to

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.setPen( Qt::red );
  painter.drawRect( printer.pageRect() );
  painter.drawLine( printer.pageRect().topRight(), 
    printer.pageRect().bottomLeft() );

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.


Thomas Zander said...

Backing store; really cool.

Well, not only because its a nice feature but also because Qt does it months after Java does it; who is saying there is no cross-breeding there :)

Backing store basically is a image-buffer that is drawn into and refreshed _while_ the application-widgets are still redrawing or even while the application is unresponsive. This means that if you decrypt your KMail email all window refreshes will work correctly, unlike now where the window just gets filled with the background color.

Musings of a Pragmatic Programmer 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.


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.

dghnfgj said...

Joy in warcraft leveling living comes wow lvl from having wow lvl fine emotions,wow power level trusting them,power leveling giving them power leveling the freedom of wrath of the lich king power leveling a bird in the open.wlk power leveling Joy in living can age of conan gold never be assumed as a pose,or put on from guildwars gold the outside as a mask. People who have this joy don not need maple story mesos to talk about it; they radiate it. wow gold They just live out their joy and let wow power leveling it splash its sunlight and glow into other lives as naturally as bird sings.