Results 1 to 9 of 9

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

  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:


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A progress bar into treeView or something like that.

    Quote Originally Posted by nilhcraiv View Post
    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()
    If you don't want to update the model then what do you need the model for?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:


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

    Post Re: A progress bar into treeView or something like that.

    Firstly, thanks for your answer.

    Sorry, maybe I have not explained well. Now I am creating a new QStandarItemModel and apply it with setModel. The problem is that creating a new QStandardItemModel is a long process because I'm doing it of this way:

    Qt Code:
    1. class displayInformation .....
    2. ....
    3. ....
    4.  
    5. QStandardItemModel* displayInformation::createModel(const QList<Data *> *dataList) //This QStandardItemModel is seting by setModel() in QTreeView
    6. {//Data is a class that contain all information of each item and its chils to show it in QTreeView
    7. int index = 0;
    8.  
    9. if(!dataList)
    10. return model; //model is a QStandardItemModel*
    11.  
    12. if(dataList->size()==0){
    13. model->setRowCount(0); index = 0; return model;}
    14.  
    15. if(dataList->size() < model->rowCount())//To remove a item
    16. {
    17. int check = 0;
    18. for(int i=0;i<model->rowCount();i++)
    19. {
    20. QString showText;
    21. showText = model->item(i)->text();
    22.  
    23. for(int j=0; j<buddies->size();j++)
    24. {
    25. if(showText == buddies->at(j)->getAddress().toString())
    26. {
    27. check=1;
    28. break;
    29. }
    30. }//for
    31. if(check!=1)
    32. {
    33. model->removeRow(i);//REMOVE THE ITEM
    34. break;
    35. }
    36. return model;
    37. }//If remove item
    38.  
    39. while(index < buddies->size())//To add item and its chils if it has them
    40. {
    41. if(dataList)
    42. {
    43. item = createItem(
    44. dataList->at(index)->getAddress().toString(),
    45. dataList->at(index)->getNumConnections())//I create the item whit its chils (connections)
    46. model->setItem(index, item);
    47. }
    48. index++;
    49. }
    50. return model;
    51. }//createModel
    52. .....
    53. ....
    To copy to clipboard, switch view to plain text mode 

    If I want show 100 QProgressBar as children of text items and after update each prgress of each progress Bar when the signal byttesWritten is emited, my application must perform many calculations. How I can extract each item individually and apply changes?

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


  7. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A progress bar into treeView or something like that.

    Why do you want to create a new model? If just one item in it changes, simply update this one item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:


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

    Default Re: A progress bar into treeView or something like that.

    Quote Originally Posted by wysota View Post
    Why do you want to create a new model? If just one item in it changes, simply update this one item.
    Yes, that is my problem, How I do it? How I simply update this one item? I dont know how a can update this one QModelIndex of QStandarItemModel...

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


  11. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A progress bar into treeView or something like that.

    Using QStandardItem::setData() or QAbstractItemModel::setData() depending on what you're operating on.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:


  13. #7
    Join Date
    Oct 2011
    Posts
    10
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: A progress bar into treeView or something like that.

    Thank you. I was confused because the documentation says:

    Sets the role data for the item at index to value.

    Returns true if successful; otherwise returns false.

    The dataChanged() signal should be emitted if the data was successfully set.

    The base class implementation returns false. This function and data() must be reimplemented for editable models.
    I thought for use setData() is necessary implement this virtual function because by default returns false....

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


  15. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: A progress bar into treeView or something like that.

    It returns false in QAbstractItemModel. But QStandardItemModel is a subclass of it which reimplements this method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. The following user says thank you to wysota for this useful post:


  17. #9
    Join Date
    Oct 2011
    Posts
    10
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: A progress bar into treeView or something like that.

    Thank you, setData() is what I needed.

  18. 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.