title: Print data QTextDocument and QPainter
body: <p>How can I print the <code>html</code> data using <code>QTextDocument</code>?</p>
  
  <p>My code, but returns error: </p>
  
  <pre><code>QString text_x = "Hello World!";
  
  QTextDocument *doc = new QTextDocument(this);
  doc-&gt;setUndoRedoEnabled(false);
  doc-&gt;setHtml("&lt;p&gt;&lt;span style=\"color:#000000; font-weight:600\"&gt;"+text_x+"&lt;/span&gt;&lt;/p&gt;");
  doc-&gt;setTextWidth(width());
  doc-&gt;setUseDesignMetrics(true);
  doc-&gt;setDefaultTextOption(QTextOption(Qt::AlignHCenter));
  
  QPainter *p = new QPainter(this);
  p-&gt;setRenderHint(QPainter::Antialiasing, true);
  p-&gt;begin(this);
  doc-&gt;drawContents(p);
  p-&gt;end();
  </code></pre>
  
  <p>Error: </p>
  
  <blockquote>
    <p>QPainter::pen: Painter not active QPainter::setPen: Painter not active QPainter::pen: Painter not active QPainter::setPen: Painter not active QPainter::setPen: Painter not active QPainter::setPen: Painter not active QPainter::restore: Unbalanced save/restore QPainter::end: Painter not active, aborted</p>
  </blockquote>