Qt World Summit: Register Today!

How to print with QPrinter

  • 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->setPageMargins (15,15,15,15,QPrinter::Millimeter);
        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

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

  • Lifetime Qt Champion


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

  • @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:)

Log in to reply