[Qt-interest] Two-colored cell in QTableView

Vyacheslav V. Yurkov uvv.mail at gmail.com
Tue Sep 1 11:32:39 CEST 2009


Hi,
I want to make two-colored cell in QTableView.
I made my delegate class with the following paint method:


void MyViewDelegate::paint(QPainter *painter,

const QStyleOptionViewItem &option,

const QModelIndex &index) const
{

QString text = index.model()->data(index, Qt::DisplayRole).toString();
QString l = text.left(5);
QRect myRect = option.rect;
myRect.setX(option.rect.x() + option.fontMetrics.width(l));
myRect.setWidth(option.rect.width() - option.fontMetrics.width(l));
painter->fillRect(myRect, Qt::green);
QItemDelegate::paint(painter, option, index);

}

But there is a little problem. My rectangle and previous character (the one
before the text.left(5) string) overlap.
It seems to me that there is a little margin between the border of the cell
and default delegate.
How it can be calculated?
Or is there any other better solutions how to make two-colored cells?
--
Vyacheslav V. Yurkov <uvv.mail at gmail.com>       Team Leader
Norilsk
 Tel: +79069001870

Software Development Department
Joint Stock Company "Channel-7", ISPco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090901/ae902ce7/attachment.html 


More information about the Qt-interest-old mailing list