Hi there

I'd like to draw lines between items in my list.

I try to do it in my delegate (derived from QStyledItemDelegate):


Qt Code:
  1. void MembersListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
  2. if(!index.isValid())
  3. return;
  4.  
  5. painter->save();
  6. painter->setRenderHint(QPainter::Antialiasing);
  7.  
  8. QStyleOptionViewItemV4 opt = option;
  9. QStyledItemDelegate::initStyleOption(&opt, index);
  10.  
  11. // ...
  12.  
  13. // seperation lines
  14. QPen linePen(Qt::gray);
  15. painter->setPen(linePen);
  16. painter->drawLine(0, opt.rect.height(), opt.rect.width(), opt.rect.height());
  17.  
  18. painter->restore();
  19. }
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