title: Word Wrapping Qt Qlabel text in a HTML <td> element
body: <p><strong>Intro:</strong></p>
  
  <p>I am trying to draw paginated forum posts in QT. Some of my initial efforts resulted in a <code>QFrame</code> with nested labels (a screenshot is shown <a href="https://stackoverflow.com/questions/11677499/pyside-qt-auto-vertical-growth-for-textedit-widget-and-spacing-between-widgets">here</a>). Since then I have had to intermix quotes with regular text and I need dynamic labels to do that in my current approach(i.e., a post instance may have 5 quotes and 7 regular text = 13 <code>QLabel</code>s, and each time I draw a new post instance I recreate all the <code>QLabel</code>s). Creating and destroying QLabels is quite expensive and I see a visual lag.</p>
  
  <p>So I have decided to try and do it in a single <code>QLabel</code> using <code>HTML</code>. I chose  the approach outlined <a href="http://www.microbion.co.uk/web/vertline.htm" rel="nofollow noreferrer">here</a> to seperate the post meta data and the post body using a emulated vertical line. </p>
  
  <p>The vertical line works fine, however I can't get the post body to text wrap. I have a suspicion that QT's html engine is going to be tricky to coerce, and I am not a HTML guru.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>How do I get the following code to word wrap to a fixed width (i.e., vertical growth).</p>
  
  <pre><code>from PyQt4.QtGui import QApplication, QLabel
  import sys
  
  
  html = '''
  &lt;table cellspacing="5" border="0" cellpadding="0"&gt;
  &lt;tr valign="top" align="left"&gt;
  &lt;td style="padding-right: 10px;" width="100"&gt;
    &lt;p&gt;#%s&lt;br&gt;
    &lt;b&gt;User:&lt;/b&gt; %s&lt;br&gt;
    &lt;b&gt;posted at:&lt;/b&gt; %s &lt;/p&gt;
  &lt;/td&gt;
  &lt;td width="1" bgcolor="#00FFFF"&gt;&lt;BR&gt;&lt;/td&gt;
  &lt;td style="padding-left: 10px;" width="100" valign="top" align="left"&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum. &lt;/p&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  ''' % (1, "hassan", "sunday") 
  
  app = QApplication(sys.argv)
  l = QLabel(html)
  l.show()
  app.exec_()
  sys.exit()
  </code></pre>
  
  <p>Which results in : </p>
  
  <p><img src="https://i.stack.imgur.com/Yo10U.png" alt="enter image description here"></p>
  
  <p>Note: width is not being respected as well as no word wrap.</p>
  
  <p>Oh and if you want to show off, feel free to style the post and show a quoted area as well :D </p>
  
  <p><strong>edit:</strong></p>
  
  <p>I tried altering the post body widget (instead of alterin the entire widget), it's a <code>QVBoxLayout</code> with <code>QLabel</code>s. I altered it to a single QLabel with <code>&lt;p&gt;</code> and <code>&lt;blockquote&gt;</code>. And that combo does linewrap properly. Though even with that working ok, the layout + label approach looks nicer. </p>
  
  <p>So perhaps I should ammend my design and maintain a list of Quote Widgets + regular text labels, in order to get rid of visual lag via recyling.</p>
  
  <p>Still if someone can create and style a sensible html representation of a forum post from the code above it is probably a more robust solution.</p>
  
  <p><strong>edit 2:</strong></p>
  
  <p>Whilst it might be possible to get HTML based styling to work off a single QLabel in my case, after trying to get it working I have come to the conclusion that a multi QLabel approach lays things out in a more controlled fashion, without much effort on my part. I'll stick to this.
  /</p>