{
public:
inline JobViewDelegate
(MainWindow
*mainWindow
) : QItemDelegate(mainWindow
){}
{
if (index.column() != 1) {
return;
}
QRect rect
= option.
rect;
QSize size
(rect.
width()*3/4,rect.
height()*3/4);
rect.setSize(size);
progressBarOption.
state = QStyle::State_Enabled;
progressBarOption.
direction = QApplication::layoutDirection();
progressBarOption.rect =rect;
progressBarOption.
fontMetrics = QApplication::fontMetrics();
QPalette pal
= progressBarOption.
palette;
col.setNamedColor("#05B8CC");
//pal.setColor(QPalette::HighlightedText,Qt::black);
progressBarOption.palette = pal;
progressBarOption.version = 2 ;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
int progress = index.data(Qt::DisplayRole).toInt();
// Set the progress and text values of the style option.
progressBarOption.progress = progress < 0 ? 0 : progress;
progressBarOption.
text = QString("%1%").
arg(progressBarOption.
progress);
// Draw the progress bar onto the view.
QApplication::style()->drawControl
(QStyle::CE_ProgressBar,
&progressBarOption, painter,
0);
}
};
class JobViewDelegate : public QItemDelegate
{
public:
inline JobViewDelegate(MainWindow *mainWindow) : QItemDelegate(mainWindow){}
inline void paint(QPainter *painter,const QStyleOptionViewItem &option,const QModelIndex &index) const
{
QProgressBar progressbar;
if (index.column() != 1) {
QItemDelegate::paint(painter, option, index);
return;
}
QStyleOptionProgressBarV2 progressBarOption;
QRect rect = option.rect;
QSize size(rect.width()*3/4,rect.height()*3/4);
rect.setSize(size);
progressBarOption.state = QStyle::State_Enabled;
progressBarOption.direction = QApplication::layoutDirection();
progressBarOption.rect =rect;
progressBarOption.fontMetrics = QApplication::fontMetrics();
QPalette pal = progressBarOption.palette;
QColor col;
col.setNamedColor("#05B8CC");
pal.setColor(QPalette::Highlight,col);
//pal.setColor(QPalette::HighlightedText,Qt::black);
progressBarOption.palette = pal;
progressBarOption.type = QStyleOption::SO_ProgressBar;
progressBarOption.version = 2 ;
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
QModelIndex ind = index.parent();
int progress = index.data(Qt::DisplayRole).toInt();
// Set the progress and text values of the style option.
progressBarOption.progress = progress < 0 ? 0 : progress;
progressBarOption.text = QString("%1%").arg(progressBarOption.progress);
// Draw the progress bar onto the view.
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter,0);
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks