Depending on you have implemented your model/view, you might be able to connect the QAbstractItemModel::dataChanged
signal to a slot that cycles through every selected item. Not every version of setData emits this signal, but you can opt to do so if you override it.
Take a look at the source code for QTableWidgetItem::setData for an example. It's in the qtablewidget.cpp file.
Edit: Alternatively, you could key in on either the delegate's closeEditor or commitData signals to intercept the editor's value and apply it to every selected item. You would have to subclass QTableView to accomplish this, so here's a little sample code to get you started inspired from here:
class MyTableView : public QTableView {
Q_OBJECT
public:
explicit MyTableView(QWidget* parent = 0) : QTableView(parent) {
connect(this->itemDelegate(), SIGNAL(closeEditor(QWidget*)),
this, SLOT(editMultipleItems(QWidget*)));
}
public slots:
void editMultipleItems(QWidget* editor) {
QLineEdit* myeditor = qobject_cast<QLineEdit*>(editor); //recast to whatever widget was actually used
if(myeditor != 0) {
foreach(const QModelIndex& index, this->selectionModel()->selectedIndexes()) {
QVariant v(myeditor->text());
model()->setData(index, v, Qt::EditRole);
}
}
}
};
As a third option, you can override QStyledItemDelegate with a special case for multiple selections, then customize setModelData() to edit every selected item instead of just the one that received the edit trigger.
You could also combine the second and third options by having the trivially subclassed QStyleItemDelegate::setModelData() emit a signal connected to your MyTableView's multiItemEdit slot with the new value.