Print HTML content

  • Hi

    I try to print HTML content combined with inline CSS.

    • If I print QWebview directly, render is OK (i.e. CSS display:block renders correctly)

    • If I print just part of doc. using QTextDocument
      @QTextDocument htmlDocument = frame->findFirstElement("#qtprint");

    Correct me if I'm wrong, I think this is due to "RichText limitations":
    => css "display" not supported
    => How to use "QWebview rendering" just for a part of HTML?

    <div id="qtprint">
    <style type="text/css">
    .mystyle { display:block; height:200px; background:#800000; color:#FFF; padding:2px 5px; }
    <span class="mystyle">Test</span>

    NB: the only solution I found is to use view->print(printer); with specific print CSS file to hide everything except the DIV #qtprint
    => i.e. div { display:none; } + div#qtprint { display:block; }
    But it would be better and safer to load & print only the necessary code

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.