[PyQt] Want to change multiple cells in QTableView at once in
custom Model/View
Hans-Peter Jansen
hpj at urpla.net
Sat Oct 3 22:45:17 BST 2009
Am Samstag 03 Oktober 2009 schrieb bvz:
> I had a version of my spreadsheet style app (in which I handled all of
> the updating of the table manually) that allowed me to set the value of
> multiple cells at once.
>
> (if the user selected multiple cells and entered, say, "bob" then all the
> selected cells would be updated to contain "bob".)
>
> I managed to do this by using a for cellIndex in self.selectedIndexes()
> loop inside a method called by the
> QTableWidget.itemChanged(QTableWidgetItem *) signal.
>
>
> Old code:
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> self.blockSignals(True)
> value = cell.text()
> dataType = cell.dataType
> for cellIndex in self.selectedIndexes():
> currentCell = self.item(cellIndex.row(), cellIndex.column())
> if currentCell.dataType == dataType: # Only update cells of
> the same data type
> currentCell.update_parameter_object(value)
> self.blockSignals(False)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Now I have it all set up to use the model/view system and it is all much
> better. Except that I can't seem to figure out how to mimic that one
> feature. The data() method that I reimplemented in the model only
> receives the index of the currently selected cell. Is there any way of
> finding out in the model which cells are selected in the view?
That sounds, like you're after self.selectionModel()...
Pete
More information about the PyQt
mailing list