Results 1 to 3 of 3

Thread: print/painter question

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default print/painter question

    Hi everyone.

    I am trying to learn how to print with qt. I have made some progress. But I have a problem that I cant solve:
    somewhere in my print function I have to search a database and copy each record to my sheet of paper one after the other. Each record has its own length and I dont know their size. The text of each record its drawn in one rectangle one after the other. But how can I know the height of the rectangles? if one record has a lot of text it can stay to big and then the next record will be written above it.
    Example:

    while (query.next())
    {
    painter.drawText(x,y,w,h,Qt::AlignTop | Qt::TextWordWrap,query.value(1).toString();
    }

    can someone give me an hint please?

    thanks
    daniel

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: print/painter question

    Hi,

    see QFontMetrics. It provides the informations you need. Also you could use a QTextDocument. But that is only advisable if you have more complicated texts.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: print/painter question

    You'll have to cache your database returns. Once you have them all stored, you can examine their length (or you can do this as they're received) then make a second pass over the collection to actually paint it, once the size of their contents is known.

    Actually, accessing a database while rendering is problematic, at best. You'd be better off separating database accesses from printing and other rendering calls.

Similar Threads

  1. painter->setRasterOp()
    By shruthi in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2010, 07:13
  2. Cancelling Long-running Print/Print Preview
    By ChrisW67 in forum Newbie
    Replies: 4
    Last Post: 16th June 2009, 23:05
  3. Painter brush question
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 22nd October 2008, 07:39
  4. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 13:47
  5. Painter not active!
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 30th March 2006, 15:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.