[Interest] Multicolored text in a QTableView cell?

Marcelo Estanislau Geyer estanisgeyer at hotmail.com
Wed Jun 13 19:21:00 CEST 2012


Hi,

Use role Qt::ForegroundRole and Qt::BackgroundRole for implement this, ex:

QVariant MccModel::data(const QModelIndex &index, int role) const
{
    if ( role == Qt::BackgroundRole ){
        return QVariant(QColor(200,200,200)); 
}

> Date: Wed, 13 Jun 2012 10:27:20 -0500
> From: schumann at fnal.gov
> To: interest at qt-project.org; development at qt-project.org
> Subject: [Interest] Multicolored text in a QTableView cell?
> 
> 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?
> 
> Sincerely,
> Carl Schumann
> 
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120613/a308bc0c/attachment.html>


More information about the Interest mailing list