Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QProgressBar>
- #include <QModelIndex>
- #include <QStyleOptionProgressBarV2>
- #include <QApplication>
- #include <QDebug>
- #include <progress_delegate.hh>
- ProgressDelegate::ProgressDelegate (QObject *parent) : QItemDelegate (parent) {
- // nothing to do
- }
- void ProgressDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
- // only for column 1
- if ( index.column() != 1 ) {
- QItemDelegate::paint ( painter, option, index );
- return;
- }
- // first get the value
- QVariant value = index.model()->data(index, Qt::DisplayRole);
- // is it already completed?
- if ( value.toString() == tr("completed") ) {
- // yes, let the super class paint it normally
- QItemDelegate::paint ( painter, option, index );
- }
- else {
- QStyleOptionProgressBarV2 new_options;
- // normal range
- new_options.minimum = 0;
- new_options.maximum = 100;
- // default size
- new_options.rect = option.rect;
- // the current progress
- new_options.progress = value.toInt();
- // show text too. we show a "42%" text
- new_options.textVisible = true;
- new_options.text = value.toString() + "%";
- // draw the actual control
- QApplication::style()->drawControl (QStyle::CE_ProgressBar, &new_options, painter, 0);
- }
- }
Add Comment
Please, Sign In to add comment