QItemDelegate edit某个控件后把数据写回model
QWidget *TrackDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == durationColumn) {
//QTimeEdit *timeEdit = new QTimeEdit(parent);
QComboBox *timeEdit = new QComboBox(parent);
//timeEdit->installEventFilter(const_cast<TrackDelegate*>(this));
timeEdit->setObjectName("timeEdit");
// timeEdit->setDisplayFormat("mm:ss");
// connect(timeEdit, SIGNAL(editingFinished()),
// this, SLOT(commitAndCloseEditor()));
timeEdit->insertItem(0,"test1");
timeEdit->insertItem(1,"test2");
return timeEdit;
} else {
return QItemDelegate::createEditor(parent, option, index);
}
}
void TrackDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
if (index.column() == durationColumn) {
QComboBox *timeEdit = qobject_cast<QComboBox *>(editor);
timeEdit->setCurrentIndex(1);
// int secs = index.model()->data(index, Qt::DisplayRole).toInt();
// QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor);
// timeEdit->setTime(QTime(0, secs / 60, secs % 60));
} else {
QItemDelegate::setEditorData(editor, index);
}
} void TrackDelegate::setModelData(QWidget *editor,QAbstractItemModel *model,
const QModelIndex &index) const
{
if (index.column() == durationColumn) {
// QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor);
// QTime time = timeEdit->time();
// int secs = (time.minute() * 60) + time.second();
// model->setData(index, secs);
} else {
QItemDelegate::setModelData(editor, model, index);
}
}
上述三个方法是实现tableview编辑某个单元格出现控件的主要方法
其中第三个方法TrackDelegate::setModelData
是实现把编辑的控件发的数据写回到model中,但这个方法什么时候会调用?
当你编辑完控件后点击tableview其他单元格后会调用该方法
或者代码添加emit commitData(editor);就会立马执行该方法。
QItemDelegate edit某个控件后把数据写回model的更多相关文章
- 在DevExpress程序中使用Winform分页控件直接录入数据并保存
一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...
- VS2015 C++ 获取 Edit Control 控件的文本内容,以及把获取到的CString类型的内容转换为 int 型
UpdateData(true); //读取编辑框内容,只要建立好控件变量后调用这个函数使能,系统就会自动把内容存在变量里 //这里我给 Edit Control 控件创建了一个CString类型.V ...
- c#中DropDownList控件绑定枚举数据
c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...
- input绑定datapicker控件后input再绑定blur或者mouseout等问题
input绑定datapicker控件后input再绑定blur或者mouseout等问题 问题描述:今天在修改一个东西的时候需要给一个input输入域绑定blur事件,从而当它失去焦点后动态修改其中 ...
- SharePoint2010沙盒解决方案基础开发——关于TreeView树形控件读取列表数据(树形导航)的webpart开发及问题
转:http://blog.csdn.net/miragesky2049/article/details/7204882 SharePoint2010沙盒解决方案基础开发--关于TreeView树形控 ...
- 机房收费系统——在VB中将MSHFlexGrid控件中的数据导出到Excel
机房收费系统中,好多查询的窗体都包含同一个功能:将数据库中查询到的数据显示在MSHFlexGrid控件中,然后再把MSHFlexGrid控件中的数据导出到Excel表格中. 虽然之前做过学生信息管理系 ...
- Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员
Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员 1. 配置server连接权限 1 2. 配置数据库权限 1 3. 设置表格/视图安全性 2 1. ...
- SQL C# nvarchar类型转换为int类型 多表查询的问题,查询结果到新表,TXT数据读取到控件和数据库,生成在控件中的数据如何存到TXT文件中
在数据库时候我设计了学生的分数为nvarchar(50),是为了在从TXT文件中读取数据插入到数据库表时候方便,但是在后期由于涉及到统计问题,比如求平均值等,需要int类型才可以,方法是:Conver ...
- C#跨进程读取listview控件中的数据
http://www.cnblogs.com/Charltsing/p/slv32.html 欢迎交流:QQ564955427 读取标准的32位listview控件中的数据,网上已经有很多代码了.今天 ...
随机推荐
- [CSP-S模拟测试]:停不下来的团长奥尔加(DP)
题目传送门(内部题125) 输入格式 第一行一个整数$n$,含义同题中所述. 第二行$n$个整数,第$i$个数表示$p_i$,含义同题中所述. 输出格式 一行一个整数,表示答案对$1000000007 ...
- Hive SQL 语法学习与实践
Hive 介绍 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构化的数据文件映射为一张数据库表,并提供 ...
- C++多重继承实践
实践代码如下: #include <iostream> using namespace std; class Animal { private: int hash; public: Ani ...
- struts1使用select标签
今天使用struts1标签的时候总是出错,后来查了一下,好像不能和什么标签混用.就只用了html原来的标签实现 <select name="newsType_id"> ...
- Git-Runoob:Git Github
ylbtech-Git-Runoob:Git Github 1.返回顶部 1. Git 远程仓库(Github) Git 并不像 SVN 那样有个中心服务器. 目前我们使用到的 Git 命令都是在本地 ...
- DatePicker 日期选择器
用于选择或输入日期 选择日 以「日」为基本单位,基础的日期选择控件 基本单位由type属性指定.快捷选项需配置picker-options对象中的shortcuts,禁用日期通过 disabledDa ...
- EasyPHP(php集成环境)下载 v5.4.6官方安装版
EasyPHP版本:12.1(32位) PHP版本:5.4.6 MYSQL版本:5.5.27 APACHE版本:2.4.2 下载地址请点击
- 【疑难杂症】【Solved】maven-compiler-plugin 在 idea 下的问题
maven-compiler-plugin 这个插件在idea和eclipse里表现本质是一样的,但是我之前有个细节没注意到,导致我对此有误解.我之前一直以为只要配置了source和target,相应 ...
- activiti随笔记录
核心组件介绍 关键对象 1. Deployment:流程部署对象,部署一个流程时创建. 2. ProcessDefinitions:流程定义,部署成功后自动创建. 3. ...
- Kafka集群搭建和配置
Kafka配置优化 https://www.jianshu.com/p/f62099d174d9 1.安装&配置 下载tar包 解压后即可使用 修改配置文件 将server.propertie ...