[Interest] Multicolored text in a QTableView cell?

Andreas Pakulat apaku at gmx.de
Wed Jun 13 17:52:59 CEST 2012


Hi,

On Wed, Jun 13, 2012 at 5:27 PM, Carl Schumann <schumann at fnal.gov> wrote:

> Qt community,
>
> I would like to have multicolored text in a single QTableView cell.
> Since labels can support multicolored text with a rich text string I
> tried the following:
> > QVariant MccModel::data(const QModelIndex &index, int role) const
> > {
> >     if( role == Qt::DisplayRole ){
> >         return( "<font color=\"red\">red</font> and <font
> > color=\"blue\">blue</font>" );
> >     }
> >     return QVariant();
> > }
> Where MccModel subclassed from QAbstractTableModel.    This did not
> work, specifically it displayed the whole long rich text string in
> black.   How should I be doing multicolored table cells please?
>

You'll need to write your own ItemDelegate that paints according to how
your model supplies the data. You might get away with painting a QLabel
with white background into a pixmap and then painting that from your
itemdelegate into the painter. But thats just a guess and an ugly hack.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120613/9f75d377/attachment.html>


More information about the Interest mailing list