What is the difference between QItemDelegate and QStyledItemDelegate?

别说谁变了你拦得住时间么 提交于 2019-12-09 14:38:41

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/28871121/what-is-the-difference-between-qitemdelegate-and-qstyleditemdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!