I've found a solution that works. Here is the code
Qt Code:
  1. if (qVariantCanConvert<QString>( index.data() ) ) {
  2. QString htmlText = qVariantValue<QString>(index.data());
  3. qtd.setHtml(htmlText);
  4. qtd.setTextWidth(-1);
  5. QSize toRet;
  6. toRet.setWidth( ceil( qtd.idealWidth() ) );
  7. toRet.setHeight( ceil( qtd.size().height() ) );
  8. return toRet;
  9. } else {
  10. return QItemDelegate::sizeHint(option, index);
  11. }
To copy to clipboard, switch view to plain text mode 
I'm sure there might be a better way, but this seems to work. The QTextDocument gives back a QSizeF, which means it might round down when it should be rounding up all the time. If someone knows of a better way to do this, I'm all ears.