Qt之模型/视图(自定义风格)
来源:互联网 发布:网络歌曲 老公你辛苦了 编辑:程序博客网 时间:2024/05/22 20:28
void DetailProgressBar::paint(QPainter *painter, constQStyleOptionViewItem &option, const QModelIndex &index)const
{
QStyleOptionViewItem view_option(option);
if (view_option.state & QStyle::State_HasFocus) {
view_option.state = view_option.state ^QStyle::State_HasFocus;
}
QStyledItemDelegate::paint(painter, view_option, index);
if (index.column() == 1) {
const QAbstractItemModel *item_model = index.model();
QModelIndex index1 = item_model->index(index.row(), 2,QModelIndex());
QString name = item_model->data(index1,Qt::DisplayRole).toString();
QModelIndex index2 = item_model->index(index.row(), 4,QModelIndex());
qint64 total_size = item_model->data(index2,Qt::DisplayRole).toLongLong();
QModelIndex index3 = item_model->index(index.row(), 5,QModelIndex());
double speed = item_model->data(index3,Qt::DisplayRole).toDouble();
QModelIndex index4 = item_model->index(index.row(), 3,QModelIndex());
qint64 size = item_model->data(index4,Qt::DisplayRole).toLongLong();
QString str_speed = Util::getSpeed(speed);
if(total_size <= 0)
total_size = 1;
double d_size = (size*1.0)/total_size;
QString q_size = QString::number(d_size, 'f', 2);
qint64 progress = q_size.toDouble() * 100;
if(progress > 100)
{
progress = 100;
}
//设置进度条的风格
QStyleOptionProgressBar progress_bar_option;
progress_bar_option.textAlignment = Qt::AlignCenter;
progress_bar_option.rect = QRect(option.rect.x()+5,option.rect.y()+option.rect.height()-4-6, option.rect.width()-20, 6);
progress_bar_option.minimum = 0;
progress_bar_option.maximum = 100;
progress_bar_option.progress = progress;
painter->drawText(QRect(option.rect.x()+5,option.rect.y()+4, option.rect.width(), 16),QString("%1").arg(name));
painter->drawText(QRect(option.rect.right()-50,option.rect.y()+4, option.rect.width(), 16),QString("%1").arg(str_speed));
QProgressBar progress_bar;
//绘制进度条
QApplication::style()->drawControl(QStyle::CE_ProgressBar,&progress_bar_option, painter, &progress_bar);
}
}
1、进度条样式
QProgressBar{
border:none;
background:rgb(210, 225, 240);
border-radius:3px;
text-align:center;
}
QProgressBar::chunk {
background:rgb(60, 140, 220);
border-radius:3px;
}
2、进度条文本
注:
阅读全文
0 0
- Qt之模型/视图(自定义风格)
- Qt之模型/视图(自定义风格)
- Qt之模型/视图(自定义风格)
- Qt之模型/视图(自定义风格)
- Qt之模型/视图(自定义进度条)
- Qt之模型/视图(自定义按钮)
- Qt之模型/视图(自定义按钮)
- Qt之模型/视图
- Qt之模型/视图
- Qt之模型/视图
- Qt之模型/视图
- Qt之模型/视图
- Qt学习:项视图类之自定义模型
- Qt之模型/视图(委托)
- Qt之模型/视图(委托)
- Qt之模型/视图(委托)
- Qt之模型/视图(委托)
- Qt之模型/视图(实时更新数据)
- PHP之引用
- Linux进程通信之管道(匿名,命名)
- 3.3 频率抽取基2-FFT
- Java实现将多个文件压缩成zip文件
- 微信/app环境下为何文字莫名其妙地居中?记个align-self/align-items的坑
- Qt之模型/视图(自定义风格)
- Cocos2d-x中替换动画(Armature)中的节点与粒子
- Java实现FTP上传图片到服务器
- 工具(五):日期时间操作工具类
- 3.6 FFT算法中的对称性
- mac XMind 保存报错解决方案
- 关于JavaScript没有块级作用域的分析
- 第一个只出现一次的字符位置和字符流中第一个不重复的字符
- Linux Tips几则