PDA

View Full Version : print/painter question



beirrascan
3rd November 2010, 21:31
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

Lykurg
3rd November 2010, 21:51
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.

SixDegrees
3rd November 2010, 21:53
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.