Hi there
I'd like to draw lines between items in my list.
I try to do it in my delegate (derived from QStyledItemDelegate):
if(!index.isValid())
return;
painter->save();
painter
->setRenderHint
(QPainter::Antialiasing);
QStyleOptionViewItemV4 opt = option;
QStyledItemDelegate::initStyleOption(&opt, index);
// ...
// seperation lines
painter->setPen(linePen);
painter->drawLine(0, opt.rect.height(), opt.rect.width(), opt.rect.height());
painter->restore();
}
void MembersListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
if(!index.isValid())
return;
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QStyleOptionViewItemV4 opt = option;
QStyledItemDelegate::initStyleOption(&opt, index);
// ...
// seperation lines
QPen linePen(Qt::gray);
painter->setPen(linePen);
painter->drawLine(0, opt.rect.height(), opt.rect.width(), opt.rect.height());
painter->restore();
}
To copy to clipboard, switch view to plain text mode
If I do so the line is only painted under the first item. The paint method should be called for each index and paint the line on bottom of the item.
Isn't there a ready made function for the lines between items like in QTableView::setShowGrid(bool show)?
Thaks!
Luke
Bookmarks