PDA

View Full Version : Two-colored cell in item view



UVV
3rd September 2009, 15:29
Hi,
I want to make two-colored cell in QTableView.
I made my delegate class with the following paint method:



void BitViewDelegate::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 solution how to make two-colored cells?

wysota
3rd September 2009, 16:33
For calculating such things see QStyle::styleHint().