[Qt-interest] How to change text in itemview (not in model)?

Uwe Drechsel vym at InSilmaril.de
Thu Jul 29 13:35:33 CEST 2010


Hi,

basically I want to have an itemview with each item showing a plaintext
version of the richtext QString available in the model.

Is there a simple way to just change the text?


So far I experimented with a delegate, but now the selection lacks all
decoration compared to default implementation:

void TreeDelegate::paint(QPainter *painter, const QStyleOptionViewItem
&option, const QModelIndex &index) const
{
    painter->save();

    QRectF rect=option.rect;

    TreeItem *ti=((TreeModel*)index.model())->getItem(index);
    QString text=ti->getHeadingPlain();

    // Paint highlighted, if selected      
     if (option.state & QStyle::State_Selected)
        painter->fillRect(option.rect, option.palette.highlight() );

    painter->drawText(rect, Qt::AlignLeft, text );  

    painter->restore();
}

Ah, and the sizeHint is wrong, it still seems to be based on the much
longer RichText.

Thanks
Uwe



More information about the Qt-interest-old mailing list