Qt 中用代理处理Model中的数据展示形式。

The QAbstractItemDelegate class is used to display and edit data items from a model.

A QAbstractItemDelegate provides the interface and common functionality for delegates in the model/view architecture. Delegates display individual items in views, and handle the editing of model data.

The QAbstractItemDelegate class is one of the Model/View Classes and is part of Qt's model/view framework.

To render an item in a custom way, you must implement paint() and sizeHint(). The QItemDelegate class provides default implementations for these functions; if you do not need custom rendering, subclass that class instead.

We give an example of drawing a progress bar in items; in our case for a package management program.

We create the WidgetDelegate class, which inherits from QStyledItemDelegate. We do the drawing in the paint() function:

void WidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,

const QModelIndex &index) const

{

if (index.column() == 1) {

int progress = index.data().toInt();

QStyleOptionProgressBar progressBarOption;

progressBarOption.rect = option.rect;

progressBarOption.minimum = 0;

progressBarOption.maximum = 100;

progressBarOption.progress = progress;

progressBarOption.text = QString::number(progress) + "%";

progressBarOption.textVisible = true;

QApplication::style()->drawControl(QStyle::CE_ProgressBar,

&progressBarOption, painter);

} else

QStyledItemDelegate::paint(painter, option, index);

Notice that we use a QStyleOptionProgressBar and initialize its members. We can then use the current QStyle to draw it.

To provide custom editing, there are two approaches that can be used. The first approach is to create an editor widget and display it directly on top of the item. To do this you must reimplementcreateEditor() to provide an editor widget, setEditorData() to populate the editor with the data from the model, and setModelData() so that the delegate can update the model with data from the editor.

The second approach is to handle user events directly by reimplementing editorEvent().

Qt实现表格内进度条展示数据相关推荐

  1. python 全栈开发,Day36(作业讲解(大文件下载以及进度条展示),socket的更多方法介绍,验证客户端链接的合法性hmac,socketserver)...

     先来回顾一下昨天的内容 黏包现象 粘包现象的成因 : tcp协议的特点 面向流的 为了保证可靠传输 所以有很多优化的机制 无边界 所有在连接建立的基础上传递的数据之间没有界限 收发消息很有可能不完全 ...

  2. 036_python的大文件下载以及进度条展示

    复习 1.黏包现象 粘包现象的成因: tcp协议的特点,面向流的,为了保证可靠传输,所以有很多优化的机制. 无边界 所有在连接建立的基础上传递的数据之间没有界限. 收发消息很有可能不完全相等. 缓存机 ...

  3. 完成度百分比用计算机怎么算,excel表格以进度条显示百分比的教程

    在Excel中经常需要统计数据,有些有百分比项目的,如果以进度条方式显示百分比,数值大概是多少也都一目了然了,如果学会了这一做法,相信你的工作效率会提升得很快.接下来是学习啦小编为大家带来的excel ...

  4. javascript --- [FormData的使用] 文件上传进度条展示 文件上传图片即使预览

    1. 准备工作 因为要发送Ajax请求,而Ajax技术的运行需要网站环境,因此其中一个解决方案是,将页面作为网站的静态资源暴露出来,然后通过浏览器进行访问. 1.1 静态资源 使用express将pu ...

  5. Vue加element Ui 实现下载文件和进度条展示。

    <template><el-progress :percentage="percentage"></el-progress><h1> ...

  6. excel导出百万数据与进度条展示

    前言 需求:用户在UI界面上选择想要导出的列,然后点击导出按钮,就能导出用户想要的数据. 效果展示 可能会产生的问题 1.如果导出数据量较大,接口很容易造成超时. 2.如果把数据一次性装载到内存里,很 ...

  7. 知识点1: 进度条随数据变化,并添加渐变样式

    效果图: dom: // 进度条 <div class="progress" :style="styleObj1"><div class=&q ...

  8. Qt创建任务栏进度条

    一.正文 任务栏进度条是Windows7就引入的一种UI形式,通常用于显示软件当前正在执行的任务的进度(如编译程序的进度.下载任务的进度).如下: 在Qt中使用任务栏进度条也是非常容易的一件事情.Qt ...

  9. cocosCreator 用进度条展示场景加载进度

    代码如下: onLoad () {var _this = this;_this.beginGame = cc.find("Canvas/bg/begin");_this.progr ...

最新文章

  1. 认识一下SAP的Area Menu
  2. CSS父级子级学习总结
  3. 计算器是如何计算sin、cos等科学函数的值呢?
  4. 使用Gson对复杂json对象的成员进行删选
  5. SCCM 2012 SP1系列(十六)资产管理和远程管理
  6. 【学习笔记】ODATA
  7. php预处理器,【 PHP 】PHP(超文本预处理器)新版下载 - U大师
  8. android WIFI信息获取
  9. jquery --- 收缩兄弟元素
  10. ssh免密登录配置方法及配置
  11. MySQL创建不了计划任务_MySQL创建定时任务(或计划任务)
  12. mysql 5.1版本无innodb trx_MySQL 5.7: Innodb 事务子系统优化-阿里云开发者社区
  13. java tcp ip通信_Java中Socket实现TCP/IP协议的通信
  14. HDU 4539 郑厂长系列故事——排兵布阵 —— 状压DP
  15. cp命令强制覆盖方式实现
  16. XP框架开启debug模式_推荐一个兼容性强完美支持XP框架的安卓模拟器,一直在用!...
  17. android 强制打开gps定位_Android开发之android_gps定位服务简单实现
  18. 方向余弦,向量夹角,向量的投影
  19. 计算机网络基本原理pdf,自考计算机网络基本原理课程学习指引.pdf
  20. tabbar角标 小程序_关于小程序tabbar不支持传参的处理办法

热门文章

  1. Oracle表空间基础(4)
  2. Android设置透明效果的三种方法(转)
  3. android开发环境的调研
  4. 浏览器一直不停的异步请求(环境:vs.net mvc)
  5. 以服务器时间为基准显示到某一时间的倒计时
  6. 用PD进行数据库建模经验总结
  7. javascript 将页面上的Table导出保存为Excel (无格式)
  8. 创建完全受信任的InfoPath表单
  9. redis远程链接(NOAUTH Authentication required)
  10. 什么样的项目适合自动化测试