PDA

View Full Version : Sinchronize a QTableView with a QDataWidgetMapper (sharing the same model)



aguleo
4th March 2014, 21:38
Hi,
I have a QTableView and a QDataWidgetMapper that share the same model (QSqlTableModel).

This code allows sinchronization when i click on the table:


connect(view->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) , mapper, SLOT(setCurrentModelIndex(QModelIndex)));


What is the equivalent connect to use when changing the current index in the QDataWidgetMapper???

anda_skoa
5th March 2014, 09:10
You connect a slot to the currentIndexChanged() of the mapper, use the passed int as a row in your table, let the model create a QModelIndex for that and call select and/or setCurrentIndex on the view's item selection model.

Cheers,
_

aguleo
5th March 2014, 13:44
I did that.
I was just hopping for a more "autommatic" solution, like the one presented for the view.
Any way ... it's working.
Thanks

anda_skoa
5th March 2014, 16:03
Yeah, it is strange. I was expecting an overloaded currentChangedSIgnal() signal with a QModelIndex, but I guess the problem is that the mapper always makes more than one "cell" current (all columns in that row it has widget mappings for).

Cheers,
_