[Qt-interest] Printing (tables) with Qt4

Israel Brewster israel at frontierflying.com
Tue Nov 17 17:55:54 CET 2009


On Nov 16, 2009, at 4:38 PM, Manuel Argüelles wrote:

> Hello List,
>
> I'm relative new to qt and so far it has been a nice experience,  
> however I'm
> having some problems with printing.
>
> I followed the guide about printing
> (http://doc.trolltech.com/4.5/printing.html) and I understand how to  
> set up
> the printer (QPrinter) and settings with QPrintDialog. Also
> QPrintPreviewDialog seems easy too (haven't tried it yet).
>
> My problem is that I have a big QTableView that I need to print, I  
> tried to
> use the render method but it placed a really small image of the  
> table with the
> scroll bars, I tried to set the QRegion to pageRect() but it almost  
> crashed my
> pc (everything got really slow and I had to terminate it)
>
> How can I print a table with headers and grid, and how can I tell  
> when it is
> time to call newPage()?
>
> I read somewhere that I must write to the QPainter directly, this  
> means using
> the drawText method right? but then I'll have to give the  
> coordinates for
> every text, and how can I know how much did it take? I also read  
> about using a
> QTextDocument but I haven't read much about it. I also read about  
> using html,
> but the same applies....
>
> Could someone please give me any hits or point me to some urls with  
> example
> about this?
>

The approach I took with this was to make a QTextDocument, insert a  
QTextTable, and then go through and populate the table with the  
contents of the QTableView. You then print the QTextDocument, and it  
takes care of page breaks and the like. It actually turned out to be  
much easier than I was expecting, although it did take some fiddling  
with the column widths and table borders/spacing to get it right for  
me. That could have just been me being picky about exactly what the  
output looked like though :)

>
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091117/ca304e36/attachment.bin 
-------------- next part --------------




More information about the Qt-interest-old mailing list