(SOLVED) Print problem with QGraphicsScene without using QPrintDialog!
-
I have an strange problem with printing a QGraphicsScene!
If i comment printDialog.exec() line, i just have Qt text on output without the whole things i have inside my scene on my <HP printer> but if i output the result to <Microsoft XPS Document Writer>, it works fine and i have correct output on xps file.
If i uncomment it , a dialog appears (what i don't want!) and even if i cancel it or close it, i still have correct output plus "Qt Here" text!
any idea about printDialog.exec() ?! what does it do to printer even when i close it or cancel it ?
@
QPrinter printer(QPrinter::HighResolution);
printer.setPaperSize(QPrinter::A4);printer.setResolution(600); printer.setOrientation(QPrinter::Portrait); printer.setPrinterName("HP LaserJet 1010"); printer.setFullPage(true); QRectF pageRect(23,16, 748,1088);// = printer.pageRect(); QGraphicsScene m_scene_print(pageRect); .... some code .... QPrintDialog printDialog( &printer,this ); printDialog.exec(); QPainter painter( &printer ); painter.drawText(rect(), Qt::AlignCenter, "Qt Here"); m_scene_print.render( &painter); //, printer.pageRect(), m_scene_print.sceneRect(), Qt::KeepAspectRatio );
@
-
It is possible to print without using a QPrintDialog, by directly calling QPrinter member functions to set things up. To cite from docs:
"The most important parameters are:- setOrientation() tells QPrinter which page orientation to use.
- setPaperSize() tells QPrinter what paper size to expect from the printer.
- setResolution() tells QPrinter what resolution you wish the printer to provide, in dots per inch (DPI).
- setFullPage() tells QPrinter whether you wantto deal with the full page or just with the part the printer can draw on.
- setCopyCount() tells QPrinter how many copies of the document it should print. "
Also you can set many other QPrinter properties.
Also see "QPrinterInfo":http://developer.qt.nokia.com/doc/qt-4.8/qprinterinfo.html and their two static public members.