Detailed Description:
The QStyledItemDelegate class provides display and editing facilities for data items from a model.
When displaying data from models in Qt item views, e.g., a QTableView, the individual items are drawn by a delegate. Also, when an item is edited, it provides an editor widget, which is placed on top of the item view while editing takes place. QStyledItemDelegate is the default delegate for all Qt item views, and is installed upon them when they are created.
The QStyledItemDelegate class is one of the Model/View Classes and is part of Qt’s model/view framework. The delegate allows the display and editing of items to be developed independently from the model and view.
The data of items in models are assigned an ItemDataRole; each item can store a QVariant for each role. QStyledItemDelegate implements display and editing for the most common datatypes expected by users, including booleans, integers, and strings.
The data will be drawn differently depending on which role they have in the model. The following table describes the roles and the data types the delegate can handle for each of them. It is often sufficient to ensure that the model returns appropriate data for each of the roles to determine the appearance of items in views.
QStyledItemDelegate 提供item显示或编辑的组件。
它是一个model/view框架,显示或编辑view model中的数据时,通过delegate绘制编辑。model中的data数据是ItemDataRole,对于每个item项可以写个QVariant 类的role。
数据类型的不同取决于model中的role。
方法
virtual QWidget
*createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual void
paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual void
setEditorData(QWidget *editor, const QModelIndex &index) const
virtual void
setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
virtual QSize
sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual void
updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const