How to update QTableView when rows are inserted to it
-
Hi,
The documentation doesn't specify but the implementation does emit rowsInserted. However in this case insertRows doesn't do anything so I wonder if there isn't a caching mechanism that avoids to update the view if in fact nothing has changed.
However in this case insertRows doesn't do anything so I wonder if there isn't a caching mechanism that avoids to update the view if in fact nothing has changed.
After a quick look (without pretense to be complete) I couldn't clearly see any such caching done.
Here's what I peeked at (for Qt 5.6):
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qabstractitemmodel.cpp#n2601
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qabstractitemmodel.cpp#n582I drag the items from another QTreeView .The cast is for that..
Did you mean that?Indeed I did. Have you considered handling the drag/drop events through the ordinary mechanism? Serializing on drag, then deserializing the mime data on drop?
-
However in this case insertRows doesn't do anything so I wonder if there isn't a caching mechanism that avoids to update the view if in fact nothing has changed.
After a quick look (without pretense to be complete) I couldn't clearly see any such caching done.
Here's what I peeked at (for Qt 5.6):
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qabstractitemmodel.cpp#n2601
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/itemmodels/qabstractitemmodel.cpp#n582I drag the items from another QTreeView .The cast is for that..
Did you mean that?Indeed I did. Have you considered handling the drag/drop events through the ordinary mechanism? Serializing on drag, then deserializing the mime data on drop?
@kshegunov said:
Serializing on drag, then deserializing the mime data on drop?
No i have not considered this part.
-
@kshegunov : I mean't view side caching.
@Ratzz currently you are not inserting anything through it. Like @kshegunov suggested, implement the drag and drop through the mechanism provided for model/view classes. It's described here
-
@kshegunov : I mean't view side caching.
@Ratzz currently you are not inserting anything through it. Like @kshegunov suggested, implement the drag and drop through the mechanism provided for model/view classes. It's described here
-
@kshegunov said:
Serializing on drag, then deserializing the mime data on drop?
No i have not considered this part.
No i have not considered this part.
Then I suggest you try it out. It may prove to be easier and better behaved than pulling the records directly from the tree widget. As for your current implementation, I'm at a loss why it doesn't work. Maybe the tree view is losing the selection when dragging and the selection model returns no records?
I mean't view side caching.
I see, well I didn't look at the view (obviously) but I suppose it's possible.
-
Hi
I am still wondering. Sorry.
Lets say If I dont have drag&drop.I simply append to my internal list used in model.
How will I tell the view(s) that?
I though dataChanged would do it but not even begin/endInsertRow
does it.Thanks
-
No i have not considered this part.
Then I suggest you try it out. It may prove to be easier and better behaved than pulling the records directly from the tree widget. As for your current implementation, I'm at a loss why it doesn't work. Maybe the tree view is losing the selection when dragging and the selection model returns no records?
I mean't view side caching.
I see, well I didn't look at the view (obviously) but I suppose it's possible.
@kshegunov said:
Maybe the tree view is losing the selection when dragging and the selection model returns no records?
I don't think so because the rowCount is getting updated as and when the new drop takes place.
-
Hi
I am still wondering. Sorry.
Lets say If I dont have drag&drop.I simply append to my internal list used in model.
How will I tell the view(s) that?
I though dataChanged would do it but not even begin/endInsertRow
does it.Thanks
-
On a side note, your rowCount implementation should rather return the size of your TableList, that way it's one less thing to manage.
-
On a side note, your rowCount implementation should rather return the size of your TableList, that way it's one less thing to manage.
-
In
dropEvent
called a new function from model which stores all the parameter of item when droped and emitted layoutAboutToBeChanged() before appending to my TableList and then emitted layoutChanged() which worked for me.Thanks to @kshegunov , @SGaist , @mrjj for the help.