继承QStyledItemDelegate 进度条控件重绘

来源:互联网 发布:linux dd命令拷贝硬盘 编辑:程序博客网 时间:2024/05/29 14:48
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);
0 0
原创粉丝点击