Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to print with QPrinter
Forum Updated to NodeBB v4.3 + New Features

How to print with QPrinter

Scheduled Pinned Locked Moved Qt Creator and other tools
3 Posts 2 Posters 1.7k 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
    MrLibya
    wrote on last edited by MrLibya
    #1

    Hello
    I've set every thing but the print dose not work , in the first i test it with PdfFormat and it's ok but now i want it to print it with my printer(hp printer )

    void MainWindow::SetPrinter()
    {
        printer = new QPrinter(QPrinter::HighResolution);
        printer->setPaperSize(QPrinter::A4);
    
        printer->setOrientation(QPrinter::Landscape);
        printer->setPageMargins (15,15,15,15,QPrinter::Millimeter);
        printer->setFullPage(false);
        printer->setOutputFileName("output.pdf");
        printer->setOutputFormat(QPrinter::NativeFormat); //you can use native format of system usin QPrinter::NativeFormat
        p_dialog = new QPrintDialog(printer,this);
        p_dialog->setWindowTitle("Print Document");
    
    }
    

    and the print function (not I've called the first fucntion first )

    void MainWindow::PrintCartBill()
    {
        if (p_dialog->exec() != QDialog::Accepted)
            return ;
        ...
        QPainter painter(printer); // create a painter which will paint 'on printer'.
        ... // draw text ,set pen ,set font and few other stuff
        painter.end();
    
    }
    

    but the nothing goes out with my printer ( hp printer )

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I may be wrong but since you are setting the output file name aren't you still printing to a file ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        I may be wrong but since you are setting the output file name aren't you still printing to a file ?

        M Offline
        M Offline
        MrLibya
        wrote on last edited by
        #3

        @SGaist ok thx , I've forget to remove it ( cuz i was testing was is going to print of pdf file with PdfFormat :D )
        but it seem that I've problem with my hp print , now the file is send to the print but not print ( it's hold on the pinding window ) alt text
        i will fix my printer , thx:)

        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