QTableView - Edit Multiple Cells
-
How can I allow the user to edit multiple cells in a QTableView?
I thought about connecting to the model's dataChanged signal, then setting the data for all selected cells. Then I realized that this would create an infinite loop. And I can't just block the dataChanged signal since the view won't get updated if I do.
So is there some way of doing this? Maybe there's something like a userEdited signal I don't know about. -
Hi,
There is a SelectionFilter class that should probably be used.
Did you read this doc:
"Model/View doc":http://qt-project.org/doc/qt-4.8/modelview.html#3-2-working-with-selections
On the bottom of the page a lot of examples are placed. Check those out. There will be others who encountered this issue. -
Hi,
Thanks for replying so fast. I Googled for SelectionFilter and could not find anything. I also checked all the examples I could find on QTableView, but none of them allow the user to edit multiple cells. They only edit the last cell that was selected. -
Hi,
Sorry, it's called: QItemSelectionModel
So, just a thought, but maybe in your setData function in your model, you read out the QItemSelectionModel items and change the data accordingly.
Or the other way around, in your view check if multiple items are selected and do a multicall to the setData with the indexes and new value. -
How can I avoid an infinite loop? If I listen to the dataChanged signal for when the user has changed the cell, I use setData on the other cells, but setData emits dataChanged so that the view will update, which will call setData again and so on forever.
-
@elveatles Although this question is very old, for future readers: Use a QSignalBlocker and then manually emit the dataChanged signal once after changing all the values.