Looping is not slow, what takes time is string comparison, cause you basically do brute force string searching.
As Chris mentioned in normal circumstances this can't lag your GUI.
But if you fill your tree with huge number of data there might be a few performance problems.
Possible solutions:
a) QTreeView with custom model may be faster for multiple reasons including no need for frequent memory allocation and reduced data duplication.
b) Consider using additional data structure ( temporary or permanent) to speed up large modifications. Example will be usage of hash table which will speed up your search. But keep in mind that maintenance of such data structure may actually make it even slower depending on your usage case.