16

Both classes provide display and editing facilities for data items from a model. QStyledItemDelegate is newer and the Qt documentation about QItemDelegate states that :

Note that QStyledItemDelegate has taken over the job of drawing Qt's item views. We recommend the use of QStyledItemDelegate when creating new delegates.

I am confused what's the difference between the two and why QStyledItemDelegate is preferred over QItemDelegate!

Nejat
  • 31,784
  • 12
  • 106
  • 138
  • 6
    Just to double check, have you checked the `QStyledItemDelegate vs. QItemDelegate` section of the http://doc.qt.io/qt-5/qstyleditemdelegate.html docs? – Iuliu Mar 05 '15 at 06:26
  • @luliu I have missed that part. Thanks. – Nejat Mar 05 '15 at 06:30
  • 8
    From the QItemDelegate documentation : """ The difference between them is that QStyledItemDelegate uses the current style to paint its items. We therefore recommend using QStyledItemDelegate as the base class when implementing custom delegates or when working with Qt style sheets. """ So if you are using a style sheet it won't have effects on the widgets made by a `QItemDelegate`. That's why Qt recommends using the `QStyledItemDelegate` instead. – Alex Mar 05 '15 at 06:30

1 Answers1

8

As mentioned in the QStyledItemDelegate documentation, the difference is that QStyledItemDelegate uses the current style to paint its items.

These two classes are independent alternatives to painting and providing editors for items in views. The difference between them is that QStyledItemDelegate uses the current style to paint its items. We therefore recommend using QStyledItemDelegate as the base class when implementing custom delegates or when working with Qt style sheets. The code required for either class should be equal unless the custom delegate needs to use the style for drawing.

Note that this answer is based on the comments of Iuliu and Alex

m7913d
  • 10,244
  • 7
  • 28
  • 56