(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&#40;&#41;;
        QPainter painter( &printer &#41;;
        painter.drawText(rect(), Qt::AlignCenter, "Qt Here");
        m_scene_print.render( &painter);   //, printer.pageRect(), m_scene_print.sceneRect(), Qt::KeepAspectRatio );
    

    @



  • Why you continue to print even if you reject it ? Basically the code should like
    @
    if (printDialog.exec() == QDialog::Accepted) {
    QPainter painter( &printer );
    painter.drawText(rect(), Qt::AlignCenter, "Qt Here");
    ... ETC
    }@



  • the problem is that i don't want that the user see the printDialog! but without using printDialog.exec() i don't have correct output but if use it even by pressing cancle button or closing dialog, it works correct!



  • 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.



  • Hm! it seems there was a problem with my scene ! seems loading thing inside my scene take times and if i show any dialog (even aboutQt messageBox ....) and press ok or cancel or exit , loads complete and works fine! strange! ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.