Qt World Summit: Submit your Presentation

Scale's problem while printing

  • Hi,

    I have a strange problem when trying to print to PDF : when I'm printing to a real printer, no problem, when I print to pdf printer using the QPrintDialog, no problem either...

    But when I'm trying to print directly to PDF using :

    @void pdfPrint()
    QPrinter pdfprinter(QPrinter::ScreenResolution);
    QString Filename= QFileDialog::getSaveFileName(0, "Export as PDF",QString(), "*.pdf");

    if (!Filename.isEmpty()) {
        if (QFileInfo(Filename).suffix().isEmpty())

    it's printing fine... But it's scaling down to an A6 page size !!! So it only prints on a quarter of my page and I get a PDF with everything printed fine but scaled down to the upper left quarter of the page.
    I would like my page to be an entire A4 page.
    Any hint ??? I was thinking about some DPI problem, but wasn't able to figure out how to correct it. (Already tried to change printer's resolution and everything...)

    I also tried to find a workaround using QPainter, which works fine printing with the right scaling, but isn't able to print the entire page, since I have to scroll to see the bottom part...
    @QPainter painter(&pdfprinter);
    maVue->render(&painter, maVue->pos(), QWidget::rect());@

  • So I solved my problem using some ugly workaround, for those who have the same problem, here is my way out :

            QPainter q(&pdfprinter);
            q.setRenderHint(QPainter::HighQualityAntialiasing, true);
            QWebView* tempp = new QWebView(this);
            tempp->setGeometry(QRect(QPoint(0,0),QSize(9920, 28066)));
            tempp->page()->mainFrame()->render(&q,QRect(QPoint(0,0),QSize(9920, 28066)));
            delete tempp;

    The problem now is that the quality is pretty bad... (Since I've got to magnify it 10 times to get it to the size of my page...)

    And yes, I do need a temporary QWebView for it because I can't setGeometry on my main QWebView and because I want my whole page to be displayed, not only the part displayed by my main QWebView...

    If anyone as a better solution, please, feel free to contribute.
    I won't research it further but would be happy to get a better way to do it.

Log in to reply