Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. (SOLVED) Print problem with QGraphicsScene without using QPrintDialog!

(SOLVED) Print problem with QGraphicsScene without using QPrintDialog!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maour
    wrote on last edited by
    #1

    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 );
    

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      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
      }@

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maour
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maour
            wrote on last edited by
            #5

            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! ;)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved