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的更多相关文章

  1. 在DevExpress程序中使用Winform分页控件直接录入数据并保存

    一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...

  2. VS2015 C++ 获取 Edit Control 控件的文本内容,以及把获取到的CString类型的内容转换为 int 型

    UpdateData(true); //读取编辑框内容,只要建立好控件变量后调用这个函数使能,系统就会自动把内容存在变量里 //这里我给 Edit Control 控件创建了一个CString类型.V ...

  3. c#中DropDownList控件绑定枚举数据

    c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...

  4. input绑定datapicker控件后input再绑定blur或者mouseout等问题

    input绑定datapicker控件后input再绑定blur或者mouseout等问题 问题描述:今天在修改一个东西的时候需要给一个input输入域绑定blur事件,从而当它失去焦点后动态修改其中 ...

  5. SharePoint2010沙盒解决方案基础开发——关于TreeView树形控件读取列表数据(树形导航)的webpart开发及问题

    转:http://blog.csdn.net/miragesky2049/article/details/7204882 SharePoint2010沙盒解决方案基础开发--关于TreeView树形控 ...

  6. 机房收费系统——在VB中将MSHFlexGrid控件中的数据导出到Excel

    机房收费系统中,好多查询的窗体都包含同一个功能:将数据库中查询到的数据显示在MSHFlexGrid控件中,然后再把MSHFlexGrid控件中的数据导出到Excel表格中. 虽然之前做过学生信息管理系 ...

  7. Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员

    Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员 1. 配置server连接权限 1 2. 配置数据库权限 1 3. 设置表格/视图安全性 2 1.  ...

  8. SQL C# nvarchar类型转换为int类型 多表查询的问题,查询结果到新表,TXT数据读取到控件和数据库,生成在控件中的数据如何存到TXT文件中

    在数据库时候我设计了学生的分数为nvarchar(50),是为了在从TXT文件中读取数据插入到数据库表时候方便,但是在后期由于涉及到统计问题,比如求平均值等,需要int类型才可以,方法是:Conver ...

  9. C#跨进程读取listview控件中的数据

    http://www.cnblogs.com/Charltsing/p/slv32.html 欢迎交流:QQ564955427 读取标准的32位listview控件中的数据,网上已经有很多代码了.今天 ...

随机推荐

  1. CommandLineRunner and ApplicationRunner

    1. Run spring boot as a standalone application (non-web) <?xml version="1.0" encoding=& ...

  2. JAVA_OPT理解及调优理论

    以RocketMQ的namesrv和broker启动为例,理解CMS和G1垃圾收集器下的jdk参数 CMS垃圾收集器 以RocketMQ中runserver.cmd为例,这是启动NameSrv的命令行 ...

  3. linux设置MySQL开机自动启动

    step1: 通过chkconfig --list命令查看mysqld是否在列表中: step2: 如果列表中没有mysqld这个,需要先用这个命令添加:chkconfig --add mysqld ...

  4. MacPorts镜像

    /opt/local/etc/macports/macports.conf: rsync_server pek.cn.rsync.macports.org rsync_dir macports/rel ...

  5. tensorflow实现迁移学习

    此例程出自<TensorFlow实战Google深度学习框架>6.5.2小节 卷积神经网络迁移学习. 数据集来自http://download.tensorflow.org/example ...

  6. docker —宝塔面板

    下载个单独的系统镜像 [root@git opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx-tomcat ...

  7. leetcode 509斐波那契数列

    递归方法: 时间O(2^n),空间O(logn) class Solution { public: int fib(int N) { ?N:fib(N-)+fib(N-); } }; 递归+记忆化搜索 ...

  8. leetcode 115不同的子序列

    滚动数组: /***** 下标从1开始 dp[i][j]:= numbers of subseq of S[1:j] equals T[1:i] if(s[j]==t[i]):(那么之后的子串可以是是 ...

  9. 基于java config的springSecurity--session并发控制

    原作地址:http://blog.csdn.net/xiejx618/article/details/42892951 参考资料:spring-security-reference.pdf的Sessi ...

  10. 匿名内部类 this.val$的问题

    一天偶尔在网上找到一个jar包,反编译后出现了如下的代码: public void defineAnonymousInnerClass(String name)  {    new Thread(na ...