Results 1 to 3 of 3

Thread: Update problem with QItemDelegate in QTreeView when adding rows

  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Update problem with QItemDelegate in QTreeView when adding rows

    I have a QItemDelegate set as the delegate for a column in a QTreeView. It's a progress bar showing the progress of threads that are running in the background downloading data. Now, I have a function that parses a file and adds the data to the QTreeView by adding a row to the QTreeView per parsed line in the file. Everything goes ok but for some STRANGE reason I can't isolate, the rows that are currently updating when the data is actually added freeze where they are and never update further. Subsequent rows that are processed by the threads are updated normally however.
    I use the following code to update the progress :

    Qt Code:
    1. void Knewz::updateDownloadProgress( QStandardItem* c, const int &progress )
    2. {
    3. int parent = c->parent()->row();
    4. int child = c->row();
    5. model->item( parent )->child( child, 3 )->setText( QString::number( progress ) );
    6. bool ok;
    7. int rows = model->item( parent )->rowCount();
    8. int prog = 0;
    9. int child_prog = 0;
    10. int children = 0;
    11.  
    12. for( int i = 0; i < rows; ++i ){
    13. child_prog = model->item( parent )->child( i, 3 )->text().toInt( &ok );
    14.  
    15. if( ok ){
    16. prog += child_prog;
    17. ++children;
    18. }
    19.  
    20. }
    21.  
    22. model->item( parent, 3 )->setText( QString::number( prog/rows ) );
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Valheru; 12th June 2007 at 15:55.

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

    Default Re: Update problem with QItemDelegate in QTreeView when adding rows

    Is it possible for you to provide something compilable? Could you also check if the model is updated and the problem is that the view doesn't refresh itself or the model doesn't update itself at all?

  3. #3
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Update problem with QItemDelegate in QTreeView when adding rows

    I'll try hack something together by tomorrow. I had hoped that someone already knew this problem to be honest

    I doubt that the the problem is that the view doesn't refresh itself - other progress bars carry on the very next instant. Since I'm downloading multipart files from a newsgroup over a 20 Mb connection, the progress bars go very fast since the multiparts are generally small. It's a freeze for the moment that the rows are appended to the model. I suspect that the model is turning off updating internally while the rows are being appended and it's in that time that the multiparts complete. Since they are finished by the time the model enables updating again, the download threads have already moved onto another row. But I shall try and provide something compileable, although it could be difficult. If you want, you can grab the code from svn trunk from sourceforge : https://knewz.svn.sourceforge.net/svnroot/knewz/trunk
    I realize that it is a whole program and therefor not ideal to track this one specific problem, but I think it would be hard for me to code something artificial that could reproduce this problem.

    /edit : you will need cmake and the kde4 libraries to compile this.

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.