qt 委托 delegate
2015-10-01 08:38
387 查看
委托的作用是,显示和编辑视图view中的item。
大多数情况下,view视图中的默认delegate委托已经足够了。一般不需要自定义委托。
委托的显示,是显示在view上的。
编辑,是针对model的,需要修改model中的数据。
如果项更好的控制有关项item的显示,可用在自定义model中实现,data()函数中,根据不同的role,返回不同的值。
比如:Qt::FontRole,Qt::DisplayRole等角色。
data()函数会自动的被委托调用。
这样,也能够更好的控制item的显示。
而且,也不需要实现一个自定义的委托。
如果想要更多的控制,比如在一个view中的item中,显示一个按钮,或者一个spinBox,或者其他的控件。
那么这个时候,可用使用delegate自定义委托。
QItemDelegate can be used to provide custom display features and editor widgets for item
We recommend the use of QStyledItemDelegate when creating new delegates.
更建议使用QStyleItemDelegate类,当自定义委托的时候。
When editing data in an item view, QItemDelegate provides an editor widget, which is a widget that is placed on top of the view while editing takes place
Editors are created with a QItemEditorFactory; a default static instance provided by QItemEditorFactory is installed on all item delegates.
使用委托的视图。当只是显示数据的时候,调用的委托的paint()方法,在paint()中,调用的是drawDisplay()方法,该方法只是显示text的。
只有在用户编辑item的时候,才会调用委托中的editor widget。即用户编辑item的时候,使用的是委托中的editor widget控件。这时候,view中显示的
才是editor widget控件。
大多数情况下,view视图中的默认delegate委托已经足够了。一般不需要自定义委托。
委托的显示,是显示在view上的。
编辑,是针对model的,需要修改model中的数据。
如果项更好的控制有关项item的显示,可用在自定义model中实现,data()函数中,根据不同的role,返回不同的值。
比如:Qt::FontRole,Qt::DisplayRole等角色。
data()函数会自动的被委托调用。
这样,也能够更好的控制item的显示。
而且,也不需要实现一个自定义的委托。
如果想要更多的控制,比如在一个view中的item中,显示一个按钮,或者一个spinBox,或者其他的控件。
那么这个时候,可用使用delegate自定义委托。
QItemDelegate can be used to provide custom display features and editor widgets for item
We recommend the use of QStyledItemDelegate when creating new delegates.
更建议使用QStyleItemDelegate类,当自定义委托的时候。
When editing data in an item view, QItemDelegate provides an editor widget, which is a widget that is placed on top of the view while editing takes place
Editors are created with a QItemEditorFactory; a default static instance provided by QItemEditorFactory is installed on all item delegates.
使用委托的视图。当只是显示数据的时候,调用的委托的paint()方法,在paint()中,调用的是drawDisplay()方法,该方法只是显示text的。
只有在用户编辑item的时候,才会调用委托中的editor widget。即用户编辑item的时候,使用的是委托中的editor widget控件。这时候,view中显示的
才是editor widget控件。
相关文章推荐
- qt model 中的角色 role Qt::CheckStateRole角色
- qt 代理模型 proxy model QSortFilterProxyModel
- QListWidget QTableWidget 项视图类
- pyqt5加载网路图片,不本地下载。
- qt多文档
- 软件实习笔记二(Qt简单对话框实例开发)
- 学习记录-Qt文件的读写和删除等操作
- 诡异的Qt eventFilter
- qt 子窗口访问父窗口中的成员函数、成员变量
- qt viewport window 视口 窗口
- qt model 与 view 的数据显示
- qt学习笔记
- qt model中的方法columnCount()方法
- qt model中headerData()函数的调用
- qt view是如何显示model中的数据
- Qt Creator: Interrupt/Exception caught code = 0xc00000fd
- QTP自动测试学习(一)
- QT5 学习之路06---QT5基本对话框3
- qt 子窗口调用父窗口的函数
- QT5 学习之路05---QT5基本对话框2