Results 1 to 9 of 9

Thread: A progress bar into treeView or something like that.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2011
    Posts
    10
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Unhappy A progress bar into treeView or something like that.

    Hello,

    I want to show in QTreeView a lot of QProgressBars as child of each item to indicate a processes, i.e. each item show a text in treeView, and they have QProgressBars as childs. I try it with QItemDelegate, but don't know how I individualy update each QProgressBar. I do it as follows: (I found this code searching on Internet)

    Qt Code:
    1. CustomItemDelegate::CustomItemDelegate(QObject *parent) :
    2. QItemDelegate(parent)
    3. {
    4. _state = QStyle::State_Enabled;
    5. }
    6.  
    7. void CustomItemDelegate::paint(QPainter *painter,
    8. const QStyleOptionViewItem &option,
    9. const QModelIndex &index) const
    10. {
    11. if(index.parent().isValid())
    12. {
    13. QStyleOptionProgressBarV2 progressBarOption;
    14. QRect rect = option.rect;
    15. QSize size(rect.width()*3/4,rect.height()*3/4);
    16. rect.setSize(size);
    17. progressBarOption.state = QStyle::State_Enabled;
    18. progressBarOption.direction = QApplication::layoutDirection();
    19. progressBarOption.rect =rect;
    20. progressBarOption.fontMetrics = QApplication::fontMetrics();
    21. QPalette pal = progressBarOption.palette;
    22. QColor col;
    23. col.setNamedColor("#05B8CC");
    24. pal.setColor(QPalette::Highlight,col);
    25. progressBarOption.palette = pal;
    26. progressBarOption.type = QStyleOption::SO_ProgressBar;
    27. progressBarOption.version = 2 ;
    28. progressBarOption.minimum = 0;
    29. progressBarOption.maximum = 100;
    30. progressBarOption.textAlignment = Qt::AlignCenter;
    31. progressBarOption.textVisible = true;
    32. int progress = index.data(Qt::DisplayRole).toInt();//TCP client or server must changes this value emitting signal bytesWritten(qint64)
    33. progressBarOption.progress = progress;
    34. progressBarOption.text = QString("%1%").arg(progressBarOption.progress);
    35.  
    36. // Draw the progress bar onto the view.
    37. QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter,0);
    38.  
    39. }
    40. else
    41. {
    42. QItemDelegate::paint(painter, option, index);
    43. }
    44. }
    45.  
    46. ...
    47. ...
    To copy to clipboard, switch view to plain text mode 

    and in QTreeView


    Qt Code:
    1. CustomItemDelegate* itemDelegate = new CustomItemDelegate(this);
    2. setItemDelegate( itemDelegate );//To set progressbar in childs of each item.
    3.  
    4. setModel( "a QAbstractItemModel to build the hierarchy of item");
    To copy to clipboard, switch view to plain text mode 

    In this code the progress of QProgressBar is set by text on QModelIndex index. How I can change only a progress in one ProgressBar? My application creates a TCP connection to send a file and I wish show the progress in each progressbar but I don't want update all QAbstractItemModel by setModel()

    I have searched a lot, but have not found the solution!

  2. The following user says thank you to nilhcraiv for this useful post:


Similar Threads

  1. How to use progress bar
    By bijay in forum Newbie
    Replies: 1
    Last Post: 28th March 2012, 10:44
  2. How to use progress bar
    By Ashwani in forum Newbie
    Replies: 6
    Last Post: 10th September 2010, 15:19
  3. Replies: 4
    Last Post: 11th March 2008, 11:44
  4. Reg - Progress bar
    By suresh in forum Qt Programming
    Replies: 1
    Last Post: 12th December 2006, 15:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.