I've found a solution that works. Here is the code
if (qVariantCanConvert<QString>( index.data() ) ) {
QString htmlText
= qVariantValue<QString>
(index.
data());
qtd.setHtml(htmlText);
qtd.setTextWidth(-1);
toRet.setWidth( ceil( qtd.idealWidth() ) );
toRet.setHeight( ceil( qtd.size().height() ) );
return toRet;
} else {
}
if (qVariantCanConvert<QString>( index.data() ) ) {
QString htmlText = qVariantValue<QString>(index.data());
QTextDocument qtd;
qtd.setHtml(htmlText);
qtd.setTextWidth(-1);
QSize toRet;
toRet.setWidth( ceil( qtd.idealWidth() ) );
toRet.setHeight( ceil( qtd.size().height() ) );
return toRet;
} else {
return QItemDelegate::sizeHint(option, index);
}
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.
Bookmarks