PDA

View Full Version : Computing page breaks



js
20th November 2007, 13:23
Hello,
I have to one issue in Qt3-based Kexi "printouts" plugin.
The printouts look like this http://kexi-project.org/pics/1.1.3/printing_images.png

The problem is that when you have, say, "Description" field filled with really large text that cannot fit on a single page, I need to somewhat split the text between pages.
Things taht internally deal with wordwrapping in Qt3, e.g. QTextCursor is private here. I also do not use 3rdparty replacement like kotext in this plugin.

Summing up, what I would like to have is a function like:


uint numberOfCharactersThatCanFitInARectangle(const QRect7 rect, const QString& text);

I could then paint first N characters on a QPainter and then go to another page and repeat the whole routine for the remaining text.

Thanks in advance,

Jaroslaw Staniek

wysota
20th November 2007, 13:56
Hi Jarek,

Try using QFontMetrics::boundingRect(). You'll have to call it repeatedly with different strings to find one that fits into a specified rectangle. That's more or less what's done even in Qt4 internally when calculating the amount of text that fits into a rectangle (see QItemDelegate::elidedText() or something like that - I don't see it in the docs but I remember using it, maybe QFontMetrics::elidedText() works in a similar way).