Guest User

Untitled

a guest
Jan 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <QProgressBar>
  2. #include <QModelIndex>
  3. #include <QStyleOptionProgressBarV2>
  4. #include <QApplication>
  5. #include <QDebug>
  6.  
  7. #include <progress_delegate.hh>
  8.  
  9. ProgressDelegate::ProgressDelegate (QObject *parent) : QItemDelegate (parent) {
  10. // nothing to do
  11. }
  12.  
  13.  
  14. void ProgressDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
  15. // only for column 1
  16. if ( index.column() != 1 ) {
  17. QItemDelegate::paint ( painter, option, index );
  18. return;
  19. }
  20.  
  21. // first get the value
  22. QVariant value = index.model()->data(index, Qt::DisplayRole);
  23.  
  24. // is it already completed?
  25. if ( value.toString() == tr("completed") ) {
  26. // yes, let the super class paint it normally
  27. QItemDelegate::paint ( painter, option, index );
  28. }
  29.  
  30. else {
  31. QStyleOptionProgressBarV2 new_options;
  32.  
  33. // normal range
  34. new_options.minimum = 0;
  35. new_options.maximum = 100;
  36.  
  37. // default size
  38. new_options.rect = option.rect;
  39.  
  40. // the current progress
  41. new_options.progress = value.toInt();
  42.  
  43. // show text too. we show a "42%" text
  44. new_options.textVisible = true;
  45. new_options.text = value.toString() + "%";
  46.  
  47. // draw the actual control
  48. QApplication::style()->drawControl (QStyle::CE_ProgressBar, &new_options, painter, 0);
  49. }
  50. }
Add Comment
Please, Sign In to add comment