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控件中的数据,网上已经有很多代码了.今天 ...
随机推荐
- eclipse中取消自动生成的TODO Auto-generated method stub
我们在实现接口定义的方法.Eclipse往往会自动加上一句:TODO Auto-generated method stub 每次手动删除很麻烦,我们可以设置一下,让强大的Eclipse在完成自动代码时 ...
- C++入门经典-例6.10-将多维数组转换成一维数组
1:代码如下: // 6.10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> usin ...
- js手写笔记
1.document.write(); 2.document.getElementById("").style.color="red";//sytle.font ...
- LeetCode 14. 最长公共前缀(Longest Common Prefix)
题目描述 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow ...
- 1. 参数的传入和添加 argparse.ArgumentParser()
# Edit configuration 传入的参数使用的是--file_dir picture, 获取使用的是argv.file_dir import argparse, sys def parse ...
- leetcode 11盛水最多的容器
class Solution { public: int maxArea(vector<int>& height) { //双指针法:从最宽的容器开始计算,当更窄的容器盛水量要大于 ...
- LinuxGPIO中文文档
本文来自Linux官方文档英文版,由于需要使用Linux的GPIO进行实验,我翻译了这篇文档. 本文档描述了GPIO框架的使用者接口.注意它描述了新的基于描述符的接口. 不推荐使用的基于整数的GPIO ...
- Selenium+Python的开发环境搭建
第一步:安装Python https://www.python.org/ 注意:在cmd窗口中输入python,如果不是内部或者外部命令的需要配置环境变量Path ; 右击桌面我的电脑-->属 ...
- Promise.then链式调用
let a = new Promise((resolve,reject)=>{ resolve(1) }).then((r)=>{console.log(r)}).then(()=> ...
- 阶段3 3.SpringMVC·_01.SpringMVC概述及入门案例_01.SpringMVC概述及入门案例
第二章 第三章 第四章 三层框架 springMvc是表现层