PDA

View Full Version : help report generator program



0BLACK0
21st September 2010, 10:44
hi guys i'm very new to qt programing currently i use PyQt4 (Python+Qt)

i want to ask a question about my new project "custom report generator"

i tried many ways of implementing this program in QT but every method ends with stacked in missing features

my real problem now is the reports pages can be more than 20000+ pages and i want the user to preview it before printing

when using QPrintPreviewWidget it takes too long to draw the items usually "tables with text" and you can't print custom pages from QPrintPreviewWidget something like (from page 0 to 5)

so i tried to paint in QGraphicsScene and implement my own QPrintPreviewWidget like
then render the selected rectangles "pages" to printer directly

i succeeded with that but drawing tables with text in QGraphicsScene take too long

because i'm very very Newbie i draw the table columns,rows cell by cell of "QRectF" cause i want to align and format the text within the cells by sub-classing QGraphicsTextItem()
and paint the text with custom font and bound it to specific rectangle then use QGraphicsScene.addItem() to add it

this cause the QGraphicsScene to have lot's & lot's of items and objects
when painting 70000 rows it takes 2GB of my ram then crashed :(

so is there a way to draw my table with customized text (align and font)

with better idea and doesn't have many objects to draw in QGraphicsScene()

i know that my solution is newbie that's what i said before :p

i can post sample if any one using PyQt4


hope to find better idea :confused:

thanx in advance :)

JohannesMunk
21st September 2010, 10:57
Hi!

I would create only one custom QGraphicsItem per page. In it's paintEvent you can draw everything on a QPainter just like you do when printing:

Sorry - code is cpp; can you translate that?



class Page : public QGraphicsItem {
public:
Page() {}

// You need to change that!
QRectF boundingRect() const{ return QRectF(0, 0, 50, 50); }

void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget)
{
painter->drawRect(boundingRect());
....
painter->setFont(..)
painter->drawText(..)
}
};

Page* page = new Page();
// set the content..

scene->addItem(page);

HIH

Johannes

0BLACK0
21st September 2010, 11:12
thank you :o

i will try your solution

i think the translation of your code is sub-classing QGraphicsItem() and paint my table and text
per page then add it to QGraphicsScene()

i hope this helps :cool:

tbscope
21st September 2010, 11:20
my real problem now is the reports pages can be more than 20000+ pages and i want the user to preview it before printing

I'm glad you call that the real problem.
A report of more than 20000 pages? Really? That's not a report.
And your users want to print this? Please tell why!
What can any normal human being do with a printed 20000 page report? What can any sane human being do with 20000 pages at all?

JohannesMunk
21st September 2010, 11:26
@tbscope: Excellent question. I didn't even really think about that!

Maybe he is in politics :->

Joh

JohannesMunk
21st September 2010, 11:29
Just thought about it from another perspective:

Why don't you print pages 1-5 onto a pdf Printer?

Then you will use the same method as when you are really printing <-> less misprints!

Joh

0BLACK0
21st September 2010, 11:30
What can any normal human being do with a printed 20000 page report? What can any sane human being do with 20000 pages at all?

my application generate invoices with lot's of customizations
(table formatted with custom color & text formatted with colors and align )
my company want that application to be very flexible cause we change our invoices look every 2 years at least
that's why i called it report generator :p

0BLACK0
21st September 2010, 11:36
Why don't you print pages 1-5 onto a pdf Printer?
Joh

;) i can't print on any file for security purposes beside my company want the Audit Section to Review the invoices before printing it directly to the printer

hope this helps :cool:

JohannesMunk
21st September 2010, 11:44
Would an encrypted pdf on a ramdisk do? Maybe also for the final output? Bear in mind, the virtual water footprint of each A4 sheet is 10 liters! But we are getting off topic here.

Let us know if you run into more Qt troubles!