[Qt-interest] How to mix QDataWidgetMapper & QListView on the same model

Timothy Reaves treaves at silverfieldstech.com
Sun Dec 13 06:03:06 CET 2009


On Dec 12, 2009, at 11:48 PM, Timothy Reaves wrote:

> 	I have a QSqlTableModel.  It is the model for a QListView.  I have it set to show the name column of each row.  I also have a QDataWidgetMapper, backed by the same QSqlTableModel.  I then listen for the signal from the QListView that the selection has changed.  When it does, I get the index of the new selection, and call setCurrentIndex() on the widget mapper.  This populates a form with all of the data for that row.
> 
> 	The problem I have is that when you click a row, I tell the mapper to select a current index.  The mapper saves the changes to the table model.  This forces the list view to lose its selection.  Now, why on Earth Qt decided that a submit should force all views to loose their selection is beyond me.  I think it's a flaw.  Whatever.  But is there a way out of this catch 22?  It's a very poor user experience for someone to click on a row, have it highlight, then immediately have it revert to normal.


	Oddly enough, if I click the same record a second time in the list view, that time it stays selected.



More information about the Qt-interest-old mailing list