title: How to reimplement sizeHint for bold text in a delegate? (Qt)
body: <p><strong>Short Version</strong></p>
  
  <p>Running <code>resizeColumnsToContents</code> works fine for regular text, but when I change text to bold, the columns are too narrow. How can I fix <code>sizeHint</code> in my custom delegate to take into account that my text is bold?</p>
  
  <p><strong>Details</strong></p>
  
  <p>I am using a custom delegate to make the text in a column bold. To do this, in the paint method of the delegate, in the column of interest I just run <code>option.font.setWeight(QtGui.QFont.Bold)</code>. </p>
  
  <p>When resizing columns to contents, however, the column with bolded text is too narrow. I tried to reimplement <code>sizeHint</code> in the delegate as follows, but it yields columns that are the exact same size as the default implementation:</p>
  
  <pre><code>def sizeHint(self, option, index):
      fontMetrics = option.fontMetrics  
      if index.column() == 0:
          text = index.model().data(index)
          document = QtGui.QTextDocument(text)
          document.setDefaultFont(option.font)
          return QtCore.QSize(document.idealWidth(), fontMetrics.height())
      return QtGui.QStyledItemDelegate.sizeHint(self, option, index)         
  </code></pre>
  
  <p>So, how can I get the <code>sizeHint</code> to correctly identify the width of my emboldened font? It seems I am simply sending in plain text here.   </p>
  
  <p><strong>Related Questions</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/5680047/qlabel-sizehint-is-too-small">QLabel sizehint is too small</a></p>