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

bvz bvz at c381.com
Sun Oct 4 23:35:18 BST 2009


The selectionModel will return which cells are selected... but it is a method
of the QTableView, not the QAbstractTableModel.  

So how do I get this information into my setData method in my model?  As far
as I can see, regardless of what info I can get from the selectionModel, the
setData method will only recognize one cell as being selected and will then
only update one cell (even though I may have many selected).





Hans-Peter Jansen-2 wrote:
> 
> 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
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 
> 

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



More information about the PyQt mailing list