Well, I must say, the updating mechanism of yours is really wicked..

All you really need is:
Qt Code:
  1. // member variables:
  2. // QPoint offset;
  3. // QPersistentModelIndex index;
  4.  
  5. void RectView::mousePressEvent(QMouseEvent* e)
  6. {
  7. index = indexAt(e->pos());
  8. offset = index.data().toRect().topLeft() - e->pos();
  9. }
  10.  
  11. void RectView::mouseMoveEvent(QMouseEvent* e)
  12. {
  13. if (index.isValid())
  14. {
  15. QRect r = index.data().toRect();
  16. r.moveTopLeft(e->pos());
  17. r.translate(offset);
  18. model()->setData(index, r);
  19. }
  20. }
  21.  
  22. void RectView::mouseReleaseEvent(QMouseEvent* e)
  23. {
  24. }
  25.  
  26. void RectView::paintEvent(QPaintEvent* e)
  27. {
  28. QAbstractItemView::paintEvent(e);
  29. QPainter painter(viewport());
  30. setDirtyRegion(viewport()->rect());
  31.  
  32. for (int row = 0; row < model()->rowCount(); ++row)
  33. {
  34. for (int col = 0; col < model()->columnCount(); ++col)
  35. {
  36. QModelIndex index = model()->index(row, col, QModelIndex());
  37. itemDelegate()->paint(&painter, QStyleOptionViewItem(), index);
  38. }
  39. }
  40. }
To copy to clipboard, switch view to plain text mode