Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QTreeWidget - changing the current view when adding/removing items
rooney last edited by
I want to implement an application that is listing active chat users. I tried to use QTreeWidget to display the available users.
The list itself will be updated every 2 seconds, so users that left the chat will be removed from the list and users that joined that chat will be added.
But there are some problems and I would appreciate to get some advice if anyone has an idea.
Whenever I add a user to the list, the viewport changes, so that it is recognized by the user running the application. I already tried to use scrollToItem(item, QAbstractItemView::PositionAtCenter) but that is not what I want to have. If I scroll through the list the current view should stay the same, if a new user is removed or added. Of course, if the removed/added user belongs to the current view it will change the current view. But this behaviour should not occur, if the view is somewhere in the middle of my list and the user is added at the end of the list.
Currently, if a user is added, QTreeWidget jumps to the first item of the list.
giesbert last edited by
without seeing what you exactly do ( by showing some coe) it is hard to say.
In general, if you have a model and a view and you insert an item, AFAIK this works.