Views [not] updating upon underlying structure of the model changes
I have encountered an issue that is most likely WAD but I still need to solve.
Consider this little program: https://drive.google.com/file/d/0B9MLVHQaeHKxeFBSYzVGVF9sQ0U/edit?usp=sharing
It is just fresh Qt GUI app with 2 QTreeViews and two sets of buttons for inserting/removing rows and columns on each view. The underlying models are QStandardItemModel in one view and QIdentityProxyModel in the other. The navigation is accomplished by clicking on the models - the index is stored and then used by the buttons.
Try inserting/removing rows and columns and you will notice that the views do not update right after the underlying data structure will have changed. Rather they will be updated after you hover over them. And that is the problem because in my other project I have incoming network data that updates the model data that is being displayed to user via standard Qt views. Therefore I need the views to be updated after the data changed and NOT when user hovers over them which he may not do as he may not be aware of the change.
You may notice there is the updateViews() function where I have tried to force-update the views. Neither update() nor repaint() changed anything. The former probably correctly as the documentation says but the repaint should as I understand it cause the widgets to get repainted... Is there any other way to force-update the views?
Also, the reason why I set up the proxy model is that in my project the proxies are heavily used and therefore I need to cause the view-update via them rather than via external slot/function as is the case in the example given. But if need be this could work as a work-around as well.
The rows related actions seem to work correctly. However columns insert/remove actions are problematic.
Upon further investigation of QTreeView class I have noticed that there are slots only for rowsAboutToBeRemoved/Inserted and rowsRemoved/Inserted model signals which explains why rows are ok. There are then protected slots for column count change but it apparently does not cause the content to be redrawn as well. And it would explain why the header actually move upon insert/remove of columns but contents update only when hovered over.
Is this WAD? Can the view be force to redraw upon column change as well without sub-classing the view?
It might be an unusual use case. It's a question you should ask on the interest mailing list. You'll find there Qt's developers/maintainers (this forum is more user oriented)
You could also have a look at the "bug report system":http://bugreports.qt-project.org to see if it's something known. If not you could open a new report providing a minimal compilable example that shows the behavior.
Thanks, I will use the mailing list.
One "bug":https://bugreports.qt-project.org/browse/QTBUG-31028 seems remarkably similar to this issue. But it is marked as done in Qt 5.1 RC-1. I am using 5.3 and it still is the problem. Therefore I have opened "another":https://bugreports.qt-project.org/browse/QTBUG-39261 linking that one in description and providing the example project attached to this post.
Also in my "mirror question":http://stackoverflow.com/questions/23849621/qt-views-not-updating-upon-underlying-structure-of-the-model-changes?noredirect=1#comment36710119_23849621 one guy confirms the odd behaviour.
I understand it is probably not the typical use case but I don't understand why dynamic columns should be unsupported in standard views. It might be to do with performance though.
Like I said, it's probably more of a feature that was not yet intensively used so the misbehavior was not seen.
The new report is a good idea since the other bug is QtQuick related and not QWidget