[Qt-interest] How to mix QDataWidgetMapper & QListView on the same model
Israel Brewster
israel at frontierflying.com
Mon Dec 14 18:22:35 CET 2009
On Dec 12, 2009, at 8:03 PM, Timothy Reaves wrote:
>
> 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.
Because you didn't have a selection before the second click, so it
doesn't submit anything. I have run into similar problems quite often,
typically what I find easiest is setting the submit method to manual
submit, and just calling submitAll() when I need to. Generally I find
that process saves me a lot of headaches, as well as making a variety
of things such as having a cancel or revert button much easier.
One thing to watch out for: if editing data in fields using a
QDataWidgetMapper, any changes you make are not submitted back to the
model until you call submit() (I think that's the right function) on
the mapper. So in your scenario, if you click a row, make some
changes, and then click another row, your changes are lost. At least,
that's something that I ran into back in Qt version 4.4 or
thereabouts. They may have changed this since then.
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091214/393a7a8a/attachment.bin
-------------- next part --------------
More information about the Qt-interest-old
mailing list