Hy all,
i've this class to change rows color of cells in table according their background.

I use this class in a slot from another class (main program qwidget) called every time a user clicks on a rows of a table

in the slot i've this simple code :

Qt Code:
  1. ui.mytable->setItemDelegate(new MyItemDelegate(this, CurrSelRow));
To copy to clipboard, switch view to plain text mode 

All works well, and the cells' background is changed according to paint method.

but i'm wondering :

Every time the user clicks on a row, the slot is invoked and a new delegate is instanced.

And to destroy ??
I think a lot of memory is used if the user clicks many times on a row...

Is this right ??
Is there a way to destroy the istance ??



Qt Code:
  1. class MyItemDelegate: public QItemDelegate
  2. {
  3.  
  4.  
  5. private:
  6. int myRow;
  7. public:
  8.  
  9.  
  10.  
  11. MyItemDelegate(QObject* pParent = 0, int rowitem = 0) : QItemDelegate(pParent)
  12. {
  13.  
  14. myRow = rowitem;
  15. }
  16.  
  17.  
  18. void paint(QPainter* pPainter, const QStyleOptionViewItem& rOption, const QModelIndex& rIndex) const
  19. {
  20.  
  21. if(rIndex.isValid())
  22. {
  23.  
  24. QStyleOptionViewItem ViewOption(rOption);
  25. QColor ItemBackgroundColor = rIndex.data(Qt::BackgroundRole).value<QColor>();
  26. QString ColorName = ItemBackgroundColor.name();
  27.  
  28. QString val;
  29.  
  30. if (qVariantCanConvert<QString>(rIndex.data()))
  31. val = qVariantValue<QString>(rIndex.data());
  32.  
  33. if (ItemBackgroundColor.isValid())
  34. {
  35.  
  36. if(myRow > 0)
  37. {
  38. if (rIndex.row() == myRow)
  39. {
  40. if (ItemBackgroundColor == ClassColor::getRed())
  41. {
  42. ViewOption.palette.setColor(QPalette::HighlightedText, ClassColor::getRed());
  43.  
  44. }
  45. }
  46.  
  47. }
  48.  
  49. }
  50. QItemDelegate::paint(pPainter, ViewOption, rIndex);
  51.  
  52.  
  53. }
  54.  
  55. }
  56. };
To copy to clipboard, switch view to plain text mode