[PyQt] Want to change multiple cells in QTableView at once in custom Model/View

bvz bvz at c381.com
Sat Oct 3 08:57:42 BST 2009


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?  Do I need to capture
this signal again? (I really hope not because It wound up being kind of
messy - the signal would be called for EVERY change, including changing the
color of the text and the font, which happened every time the user changed
the data).

Thanks
Ben
-- 
View this message in context: http://www.nabble.com/Want-to-change-multiple-cells-in-QTableView-at-once-in-custom-Model-View-tp25726512p25726512.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list