QStyledItemDelegate

本文详细介绍了QStyledItemDelegate类,它是Qt中用于item视图显示和编辑的标准委托类。文章解释了如何通过该类独立于模型和视图来开发item的显示和编辑功能,并列举了常见数据类型的处理方式。

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值