Results 1 to 2 of 2

Thread: Computing page breaks

  1. #1
    Join Date
    Nov 2007
    Qt products
    Qt3 Qt4
    Unix/X11 Windows

    Default Computing page breaks

    I have to one issue in Qt3-based Kexi "printouts" plugin.
    The printouts look like this

    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:

    Qt Code:
    1. uint numberOfCharactersThatCanFitInARectangle(const QRect7 rect, const QString& text);
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by wysota; 20th November 2007 at 13:52. Reason: Removed the link to docs

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Computing page breaks

    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).

  3. The following user says thank you to wysota for this useful post:

    js (20th November 2007)

Similar Threads

  1. QWidget display on 2 stack widget page
    By spawnwj in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2006, 12:07


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.