[Qt-interest] How to change text in itemview (not in model)?
Justus Best
just18 at gmx.de
Thu Jul 29 17:24:05 CEST 2010
Hi,
My solution for this would be not to override the paint method,just
reimplement
QString QStyledItemDelegate::displayText ( const QVariant & value, const
QLocale & locale ) const [virtual]
and process QVariant::String.
Regards Justus
Am 29.07.2010 13:35, schrieb Uwe Drechsel:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list