Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]print html text

[SOLVED]print html text

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.7k 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.
  • E Offline
    E Offline
    evergreen
    wrote on last edited by
    #1

    Hello,

    I want to propose an option to the user that would allow him to print the content of a QTextEdit with html content.
    I try this (Text is my QTextEdit) :
    @
    QString html = Text->toHtml();

       QPrinter printer(QPrinter::HighResolution);
       QPrintDialog printDialog(&printer; , this);
       if (printDialog.exec()) {
           QPainter painter(&printer;);
           QTextDocument textDocument;
    
           textDocument.setHtml(html);
           textDocument.print(&printer;);
       }@
    

    The dialog box opens in chose a printer, but the document created is empty.
    Could you help me understand why?

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Why are you creating a QPainter?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • E Offline
        E Offline
        evergreen
        wrote on last edited by
        #3

        Sorry, the painter is useless, I solved the problem.

        Here's the solution if some are interest :
        @
        QPrinter Printer(QPrinter::HighResolution);
        QString htmlText(Text->toHtml());
        QPrintDialog PrintDialog(&Printer;, this);
        if (PrintDialog.exec())
        {
        Printer.setFullPage(true);
        QTextDocument TextDocument;
        TextDocument.setHtml(htmlText);
        TextDocument.print(&Printer;);
        }@

        tha,ks

        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