Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView print
Forum Updated to NodeBB v4.3 + New Features

QWebView print

Scheduled Pinned Locked Moved Unsolved Qt WebKit
5 Posts 2 Posters 3.6k Views
  • 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.
  • EvgeE Offline
    EvgeE Offline
    Evge
    wrote on last edited by Evge
    #1

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

    view = new QWebView(this);
    QString html = cFile->pdfDocSell(NUM); //get html
    view->setHtml(html);
    
    printer = new QPrinter();
    printer->setPageSize(QPrinter::A4);
    printer->setPageOrientation(QPageLayout::Portrait);
    printer->setPageMargins(15.00, 10.00, 7.00, 15.00, QPrinter::Millimeter);
    printer->setResolution(QPrinter::HighResolution);
    printer->setFullPage(true);
    
    void PrintDoc::print()
    {
        printer->setOutputFormat(QPrinter::NativeFormat);
        QPrintDialog printDialog(printer, this);
        if (printDialog.exec() == QDialog::Accepted) {
            view->print(printer);
        }
    }
    

    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.
    Thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      patrik08
      wrote on last edited by patrik08
      #2

      Hi...
      is like QWebEngineView you need LAMBADA callback :-)
      http://doc.qt.io/qt-5/qwebenginepage.html#toHtml
      My solution at head from:
      https://github.com/pehohlva/QOASIS/blob/master/test/dkernel/epubview.cpp

      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?

      1 Reply Last reply
      0
      • EvgeE Offline
        EvgeE Offline
        Evge
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • P Offline
          P Offline
          patrik08
          wrote on last edited by
          #4

          Try https://github.com/pehohlva/Tiny_Edit is inside a QTextBrowser i use to play RTF format & epub page.. Markdown ...

          0_1504370696454_shooteditor.png

          1 Reply Last reply
          1
          • EvgeE Offline
            EvgeE Offline
            Evge
            wrote on last edited by
            #5

            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*)));
                preview->exec();
            

            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.

            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