Green Cell Green Cell - 1 year ago 236
Python Question

PySide QTableView setData for multiple cells

I'm using a

and sub-classed a
. When editing a cell I noticed that
only goes through the last selected cell. Is there a way to get
to work with multiple (selected) cells?

As an example of usage:

  • Select four cells from the table.

  • Begin edit on one cell.

  • Input a value and hit enter to commit.

  • Have value modify all four cells (currently it just modifies the cell that is selected last)

I tried sub-classing
, then looping through
to call them with
, but I don't know how to get the user's input value from

Here's my attempt, almost got it, just need the input value.

def closeEditor(self, editor, hint):
is_cancelled = (hint == QtGui.QAbstractItemDelegate.RevertModelCache)

if not is_cancelled:
for index in self.selectedIndexes():
if index == self.currentIndex():

input_value = ??? # Don't know how to get this from here!

self.model().setData(index, input_value, QtCore.Qt.EditRole)

return QtGui.QTableWidget.closeEditor(self, editor, hint)

Answer Source

The editor in the closeEditor signal is the widget that was used for editing.

If that is, for example a QLineEdit you can read the text of it through its text property.

One way to retrieve the property value is through QObject's property API

value ="text")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download