PDA

View Full Version : RichText Delegate and size hint for row height



solook
28th September 2011, 20:23
i use this code for auto row height :


void QTableWidget::resizeRowsToContents();
and it word good but when is use this delegate


class RichTextDelegate : public QItemDelegate
{
public:
RichTextDelegate()
{
}
void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
painter->save();
QTextDocument doc;
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid() && !value.isNull()) {
QString text;
text.append("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:'tahoma'; font-size:9pt;\">");
text.append(value.toString());
text.append("</p>");

doc.setHtml(text);
QAbstractTextDocumentLayout::PaintContext context;
doc.setPageSize( option.rect.size());
painter->setClipRect( option.rect );
painter->translate(option.rect.x(), option.rect.y());
doc.documentLayout()->draw(painter, context);
painter->restore();
}
}


row height depend on text size dont work ..

how can i set row height depend on text(height) with that delegate ?

solook
1st October 2011, 18:30
i waiting....