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 :
void Knewz
::updateDownloadProgress( QStandardItem* c,
const int &progress
) {
int parent = c->parent()->row();
int child = c->row();
model
->item
( parent
)->child
( child,
3 )->setText
( QString::number( progress
) );
bool ok;
int rows = model->item( parent )->rowCount();
int prog = 0;
int child_prog = 0;
int children = 0;
for( int i = 0; i < rows; ++i ){
child_prog = model->item( parent )->child( i, 3 )->text().toInt( &ok );
if( ok ){
prog += child_prog;
++children;
}
}
model
->item
( parent,
3 )->setText
( QString::number( prog
/rows
) );
}
void Knewz::updateDownloadProgress( QStandardItem* c, const int &progress )
{
int parent = c->parent()->row();
int child = c->row();
model->item( parent )->child( child, 3 )->setText( QString::number( progress ) );
bool ok;
int rows = model->item( parent )->rowCount();
int prog = 0;
int child_prog = 0;
int children = 0;
for( int i = 0; i < rows; ++i ){
child_prog = model->item( parent )->child( i, 3 )->text().toInt( &ok );
if( ok ){
prog += child_prog;
++children;
}
}
model->item( parent, 3 )->setText( QString::number( prog/rows ) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks