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实现的特色进度条,类似于地铁站的进度灯,可调颜色
基于python和qt实现的网课进度条源码+使用教程.zip基于python和qt实现的网课进度条源码+使用教程.zip基于python和qt实现的网课进度条源码+使用教程.zip基于python和qt实现的网课进度条源码+使用教程.zip基于python和...
使用Qt 实现复制文件 根据复制文件的大小 进度条显示复制进度。代码可以直接复用。
QT 自己写的进度条控件 (内有两种进度条,且窗体透明) QT4.5.3+ vc6.0 windows2003下编译通过
通过重写QWidget实现在按钮上的进度条,点击按钮就会在按钮上绘制进度
Qt 使用多线程QThread实现进度条
实现Qt程序对excel表格数据的快速读写,适用于数百条以上的数据记录。
使用C++ QT实现的水波进度条源码 软件架构 Qt 5.9 + msvc 2015 Windows(x32, x64)/Linux(x32, x64) 理论上Qt 5.6以上都支持 主要技术 模块 介绍 signal\slot 控件、窗体间通信,事件处理 QPainter 窗口的绘制 QFont ...
Qt案例之利用QPainter实现自定义圆形进度条,纯QPainter绘制,不包括图片,详情可参考文章:https://blog.csdn.net/didi_ya/article/details/124378255
原创demo,仅供交流学习。
Qt5.8用ftp实现上传和下载文件,并带进度条显示
Qt带进度条的启动界面
本实例详细说明了如何在Qt中使用QTableWidget绘制数据表格;并且跟源文件一起还有使用说明。对初学Qt编程的有极大的帮助。
自定义Qt圆形进度条。 非常漂亮。
用QT写的进度条demo 主要是界面比较好看
QT实现可拖拽行排序的表格,研究了一天实现的自定义控件。 效果类似QQ好友分组的拖动排序功能,非常流畅,内含我对表格的常用初始化代码和样式设置。具体内容见博客分类“Qt实用技术”内文章。
考虑程序的友好性,当程序在执行一项耗时操作时,界面应告诉用户“程序还在运行中”,那么,QT中进度对话框(QProgressDialog)可以满足要求
实现进度条带有文字百分比
Qt实现在QLabel上播放视频文件,可以拖动进度条,快进倒退,快进可以两倍快进,同时提供了多倍快进的方法。视频播放过程中,实时显示进度
本文实例为大家分享了Qt实现圆圈加载进度条的具体代码,供大家参考,具体内容如下 先看效果图: 思路:画一个占270度的圆弧,然后定义一个定时器,定时旋转坐标系,实现旋转的效果。圆弧需要使用渐变色,实现颜色...