搜索了一下,QTableView中嵌入复选框CheckBox方法有四种

第一种不能之前显示,必须双击/选中后才能显示,不适用。

第二种比较简单,通常用这种方法。

第三种只适合静态显示静态数据用

第四种比较适合扩展,它除了可以嵌入复选框,还可以通过paint()绘制其它控件,图片等自定义风格。

第一种方法是:编辑委托法

这种方法直接利用委托中重载createEditor(),激活QCheckBox,这个缺点是必须双击/选中,才能显示CheckBox控件。一般不满足我们实际中的直接显示的需要。可以参考Qt中的QSpinBoxDelegate例子。

第二种方法是:设置QAbstractTableModel的flags()函数法。

第三种方法是:用QTableView中的方法void setIndexWidget(const QModelIndex &index, QWidget *widget)来设置QCheckBox。

代码:setIndexWidget(index, new QTextEdit);

Qt Assistant 写道
The items shown in a table view, like those in the other item views, are rendered and edited using standard delegates. However, for some tasks it is sometimes useful to be able to insert widgets in a table instead. Widgets are set for particular indexes with the setIndexWidget() function, and later retrieved with indexWidget().

Qt Assistant 写道关于setIndexWidget()

Sets the given widget on the item at the given index, passing the ownership of the widget to the viewport.
If index is invalid (e.g., if you pass the root index), this function will do nothing.
The given widget's autoFillBackground property must be set to true, otherwise the widget's background will be transparent, showing both the model data and the item at the given index.
If index widget A is replaced with index widget B, index widget A will be deleted. For example, in the code snippet below, the QLineEdit object will be deleted.
setIndexWidget(index, new QLineEdit);
...
setIndexWidget(index, new QTextEdit);
This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead.

此功能只应该用来显示可视区域内对应一个数据项的静态内容。如果你想显示自定义的动态内容或执行自定义编辑器部件,子类化QItemDelegate代替。

就是说这个只适合用来做不变数据的显示,而不适合做一些会产生插入,更新,删除这样的操作的数据显示.

第四种方法是:实现QAbstractItemDelegate的paint()函数。

【Qt】QTableView中嵌入复选框CheckBox 的四种方法总结相关推荐

  1. PyQt(Python+Qt)学习随笔:复选框checkBox的tristate属性

    在Qt Designer中,tristate属性是复选框checkBox相比较于QAbstractButton多出来的唯一属性. tristate属性表示复选框是三种状态还是两种状态,如果trista ...

  2. 在word 2007中插入复选框

    在Word2007中插入复选框Checkbox 2008-10-31 12:06 要在Office 2007中插入复选框,需要先点击"Office按钮"->"Wor ...

  3. java中判断复选框是否选中_php 判断复选框checkbox是否被选中

    php 判断复选框checkbox是否被选中 复选框checkbox在php表单提交中经常被使用到,本文章通过实例向大家介绍php如何判断复选框checkbox中的值是否被选中,需要的朋友可以参考一下 ...

  4. 为tableview添加带控件的单元格如复选框checkbox与combbox单元格

    我们常常会有这样的需求,为QTableView增加复选框checkbox和选择下拉框combbox,毕竟依靠键盘输入不是很好约束其规范性.下面我们逐个来介绍.完成之后的效果如下: 一.准备TableV ...

  5. 使用CSS3美化复选框checkbox

    我们知道HTML默认的复选框样式十分简陋,而以图片代替复选框的美化方式会给页面表单的处理带来麻烦,那么本文将结合实例带您一起了解一下使用CSS3将复选框checkbox进行样式美化,并且带上超酷的滑动 ...

  6. html5复选框样式,11种炫酷CSS3复选框checkbox样式美化效果

    这是一款效果非常酷的CSS3复选框checkbox样式美化效果.该复选框美化效果共有11种.默认的复选框的样式十分不好看,该效果将复选框加一美化,带上了一些动画效果,其中一些制作为滑动按钮的样式. 使 ...

  7. 获取jQuery中的复选框值

    如何在jQuery中获取复选框的值? #1楼 尝试这个小解决方案: $("#some_id").attr("checked") ? 1 : 0; 要么 $(&q ...

  8. 使用easyui框架form控件,单选按钮radio或复选框checkbox样式问题

    为什么80%的码农都做不了架构师?>>>    easyui只提供了textbox文本框,未提供单选按钮radio或复选框checkbox控件,在使用过程中,会存在单选按钮radio ...

  9. php表单复选传值,jQuery+SpringMVC中的复选框选择与传值实例_jquery

    下面我就为大家分享一篇jQuery+SpringMVC中的复选框选择与传值实例,具有很好的参考价值,希望对大家有所帮助. 一.checkbox选择 在jQuery中,选中checkbox通用的两种方式 ...

最新文章

  1. 《Redis设计与实现》阅读笔记(二)--简单动态字符串
  2. linux c 获取进程 可执行文件路径
  3. 我的Android进阶之旅------gt;Android字符串资源中的单引號问题error: Apostrophe not preceded by 的解决的方法...
  4. Spring基于Annotation装配Bean
  5. 架构设计(2)---分布式架构的演进过程
  6. python进阶14文件路径(找不到文件)
  7. vue如何在手机上查看vue-cli构建的项目
  8. 盘点当下稳定又好用的远程控制方案,软硬全覆盖
  9. tp3.2 获取post,get,session,cookie变量
  10. 三维实景模型制作,360度全景展示
  11. 15软件班安卓课程实训总结
  12. c# timer 销毁_.NET中Timer 如何正确地被Dispose
  13. 重置CISCO 2911SEC/K9路由器密码
  14. 带你认识有源晶振的分类和英文缩写
  15. Arduino案例实操 -- 智能巡防小车(四)火焰检测功能扩展
  16. excel VBA 字典与集合(Dictionary与Collection)
  17. p4 编程语言环境配置
  18. Delphi D10 StringGrid安卓下虚拟键盘的使用
  19. Java项目:房屋租赁管理系统(java+SSM+Layui+Maven+Mysql+Jsp
  20. 你知道什么是 短路与 和 短路非吗 ???

热门文章

  1. hdu 2019 数列有序!(c语言)
  2. 【面试】iOS 开发面试题(二)
  3. Java 泛型中的? super T和? extends T
  4. 推荐《富爸爸、穷爸爸》
  5. Java 枚举(enum)
  6. python写spark_python开发sparkSQL应用
  7. mysql2 0.3.16.gem_安装mysql2时出错:无法构建gem原生扩展
  8. 360天擎默认卸载密码_装机工具老毛桃携带木马病毒 卸载安全软件进行恶意推广...
  9. 自学转行成前端工程师,三面拿下字节跳动offer
  10. 7个前端新手常见误区,千万要避开!