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

Stephen Kelly steveire at gmail.com
Thu Jul 29 14:36:16 CEST 2010


Uwe Drechsel wrote:

> 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.

Another option would be a proxy model:

http://lists.trolltech.com/pipermail/qt-interest/2010-July/025996.html

> 
> Thanks
> Uwe





More information about the Qt-interest-old mailing list