Important: Please read the Qt Code of Conduct -

QWebView print

  • Hi
    I'm trying to print a web page from QWebView.

    view = new QWebView(this);
    QString html = cFile->pdfDocSell(NUM); //get html
    printer = new QPrinter();
    printer->setPageMargins(15.00, 10.00, 7.00, 15.00, QPrinter::Millimeter);
    void PrintDoc::print()
        QPrintDialog printDialog(printer, this);
        if (printDialog.exec() == QDialog::Accepted) {

    so, rezult - > screen result A

    After, I change orientation page -> result

    Print to pdf works good.
    As you can see, the web page does not enter the page in width. The question is, what should be done to ensure that the web page on the printed page is complete.

  • Hi...
    is like QWebEngineView you need LAMBADA callback :-)
    My solution at head from:

    startHtmlGrab && image.. put in a QTextEdit && print...
    2 steep plus but is perfect...

    QT5 dont have QWebView ... after is QWebEngineView
    Wy you not use QTextBrowser or QTextEdit for document?

  • thanks, patrik08, I will try QTextBrowser
    I use Qt 5.3
    my process look something else like: data - html doc - webView - print - print page

  • Try is inside a QTextBrowser i use to play RTF format & epub page.. Markdown ...


  • this project for printing does not use any special settings that I don't have.

    Forgot to specify: I print my documents in Windows 7.
    I tried to start printing through the QPrintPreviewDialog.

    QPrintPreviewDialog *preview = new QPrintPreviewDialog(printer, this);
        connect(preview, SIGNAL(paintRequested(QPrinter*)), view, SLOT(print(QPrinter*)));

    In the preview window everything looks great, but the result of printing on paper is the same as in the screenshot. Moreover, I tried to print in OneNote and the result is just as bad.

Log in to reply