On 6/13/2012 11:51 AM, Konrad Rosenbaum wrote:
Hi,On Wednesday 13 June 2012 17:27:20 Carl Schumann wrote: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?Use a custom delegate instead: derive a class from QItemDelegate and override the paint method to do your custom drawing. If you want to use rich text you can for example use QTextDocument::drawContents as a helper. Konrad
Konrad,Thanks for the help thus far. I have done as you recommend. There must be something I don't quite get yet though as my cell text is offset from where I would expect it to be. The code for my paint method is as follows:
void MccModelItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) constOn my system I need the kludge to get the cell text positioned correctly. I have attached two screen shots to indicate the effect of the kludge. Any insights would be appreciated please. Thanks for any help.{ painter->save();QLabel text( "<font color=\"blue\">" + QString::number(index.row()) + "</font> and " "<font color=\"red\">" + QString::number(index.column()) + "</font>" );text.adjustSize();int top = option.rect.top() + (option.rect.height() - text.height()) / 2; // center text in cell vertically int left = option.rect.left() + text.height() / 3; // indent a third of the height - this is somewhat arbitary#if 1 // XXX: Kludge top += 22; left += 20; #endif QPoint render_at( left, top ); text.render( painter, render_at ); painter->restore(); return; }
Sincerely, Carl Schumann
<<attachment: results_kludge_on.png>>
<<attachment: results_kludge_off.png>>
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest