#include "customitemdelegate.h"
customItemDelegate::customItemDelegate(QObject* parent): QStyledItemDelegate(parent)
, itemButton1(new ItemButton("play"))
, itemButton2(new ItemButton("cancle"))
, itemButton3(new ItemButton("folder"))
, itemProgressBar(new ItemProgressBar())
{
connect(this, SIGNAL(signals1( const QModelIndex&)), this, SLOT(showMessage1( const QModelIndex&)));
connect(this, SIGNAL(signals2( const QModelIndex&)), this, SLOT(showMessage2( const QModelIndex&)));
connect(this, SIGNAL(signals3( const QModelIndex&)), this, SLOT(showMessage3( const QModelIndex&)));
}
void customItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem viewOption(option);
initStyleOption(&viewOption, index);
if (option.state.testFlag(QStyle::State_HasFocus))
viewOption.state = viewOption.state ^ QStyle::State_HasFocus;
switch(index.column())
{
case customTableView::NameRole: // 0 名称
{
}
break;
case customTableView::InfoRole_1: // 1 [已下载大小/]总大小
{
viewOption.displayAlignment = Qt::AlignCenter;
}
break;
case customTableView::InfoRole_2: // 2 [下载速度]
{
viewOption.displayAlignment = Qt::AlignCenter;
}
break;
case customTableView::InfoRole_3: // 3 下载进度
{
itemProgressBar->paintQProgressBar(painter, option, index);
viewOption.text = "";
}
break;
case customTableView::OperatorRole_1:// 4
{
itemButton1->paintButton(painter, option, mousePos);
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->paintButton(painter, option, mousePos);
}
break;
case customTableView::OperatorRole_3:// 6
{
itemButton3->paintButton(painter, option, mousePos);
}
break;
default:
{
}
}
QStyledItemDelegate::paint(painter, viewOption, index);
}
QSize customItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
switch(index.column())
{
case customTableView::NameRole: // 0 名称
case customTableView::InfoRole_1: // 1 [(]已下载大小/]总大小
case customTableView::InfoRole_2: // 2 [下载速度]
{
return QSize(100, 30);
}
break;
case customTableView::InfoRole_3: // 3 下载进度
{
return QSize(200, 30);
}
break;
case customTableView::OperatorRole_1:// 4
case customTableView::OperatorRole_2:// 5
case customTableView::OperatorRole_3:// 6
{
return QSize(50, 30);
}
break;
}
return QStyledItemDelegate::sizeHint(option, index);
}
bool customItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{
QMouseEvent* pEvent = static_cast<QMouseEvent*> (event);
mousePos = pEvent->pos();
if (ItemButton::withinButtonRegion(mousePos, option))
{
switch (event->type())
{
case QEvent::MouseMove:
{
switch(index.column())
{
case customTableView::OperatorRole_1:// 4
{
itemButton1->setStatusHover();
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->setStatusHover();
}
break;
case customTableView::OperatorRole_3:// 6
{
itemButton3->setStatusHover();
}
break;
}
return true;
}
break;
case QEvent::MouseButtonPress:
{
switch(index.column())
{
case customTableView::OperatorRole_1:// 4
{
itemButton1->setStatusPressed();
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->setStatusPressed();
}
break;
case customTableView::OperatorRole_3:// 6
{
itemButton3->setStatusPressed();
}
break;
}
return false;
}
break;
case QEvent::MouseButtonRelease:
{
switch(index.column())
{
case customTableView::OperatorRole_1:// 4
{
itemButton1->setStatusReleased();
emit signals1(index);
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->setStatusReleased();
emit signals2(index);
}
break;
case customTableView::OperatorRole_3:// 6
{
itemButton3->setStatusReleased();
emit signals3(index);
}
break;
}
return true;
}
break;
default:
{
switch(index.column())
{
case customTableView::OperatorRole_1:// 4
{
itemButton1->setStatusNone();
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->setStatusNone();
}
break;
case customTableView::OperatorRole_3:// 6
{
itemButton3->setStatusNone();
}
break;
}
QStyledItemDelegate::editorEvent(event, model, option, index);
return false;
}
break;
}
}
else
{
switch(index.column())
{
case customTableView::OperatorRole_1:// 4
{
itemButton1->setStatusNone();
}
break;
case customTableView::OperatorRole_2:// 5
{
itemButton2->setStatusNone();
}
break;
case customTableView::OperatorRole_3:// 6
{
没有合适的资源?快使用搜索试试~ 我知道了~
QTableViewExample.zip
共32个文件
png:18个
cpp:5个
h:4个
4星 · 超过85%的资源 需积分: 10 13 下载量 52 浏览量
2019-12-06
10:32:25
上传
评论
收藏 54KB ZIP 举报
温馨提示
QT实现自定义展示效果 https://blog.csdn.net/hzt12345hf/article/details/103366407
资源推荐
资源详情
资源评论
收起资源包目录
QTableViewExample.zip (32个子文件)
QTableViewExample.pro.user 45KB
customdatastructure.cpp 1KB
customitemdelegate.cpp 13KB
res.qrc 818B
customdatastructure.h 897B
QTableViewExample.pro 1KB
mainwindow.cpp 964B
icon
play.png 2KB
folder-hover.png 3KB
delete-hover.png 3KB
play-hover.png 3KB
file-pressed.png 3KB
cancle-pressed.png 3KB
play-pressed.png 3KB
cancle-hover.png 3KB
folder-pressed.png 3KB
delete-pressed.png 3KB
delete.png 3KB
pause-pressed.png 3KB
file.png 2KB
pause.png 2KB
file-hover.png 3KB
cancle.png 3KB
folder.png 3KB
pause-hover.png 3KB
customitemdelegate.h 3KB
mainwindow.h 457B
QTableViewExample.pro.user.4.10-pre1 24KB
customtableview.cpp 6KB
main.cpp 183B
customtableview.h 1KB
mainwindow.ui 1KB
共 32 条
- 1
资源评论
- zhouxiao20092021-04-26可以,例子,挺好的
紫藤Teng
- 粉丝: 75
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于C++的程序设计大赛天梯赛L2答案(天梯赛)
- 基于python实现的三次样条插值和均值插值法实现
- Python语言教程2-python批量图片大小处理-多文件夹
- Python语言教程1-python批量图片重命名,将后缀某几个不想要的字去除
- Space Combat Kit 太空战斗套件Unity游戏开发插件资源unitypackage C#
- Universal Device Preview 通用设备预览Unity游戏开发插件资源unitypackage
- Paladin Anim Set 圣骑士动画集Unity游戏动作动画插件资源unitypackage
- 计算机财务管理期末考报表部分题目及答案.doc
- 计算机软件维护论文.doc
- 计算机软件著作权授权书.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功