Try calling treewidget->update() in the for loop
Am not sure though if it wil work