Results 1 to 5 of 5

Thread: Proxy model / view update problem

  1. #1
    Join Date
    Apr 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Proxy model / view update problem

    Hi all,

    I am experiencing a problem with proxy models, and would greatly appreciate any help. I am not sure if I somehow missed part of the underlying concepts:

    What works:

    I have a QAbstractTableModel-derived model that is displayed in a QTableView.
    This works. I can update the model by calling beginInsertRows(), doing the changes, and then calling endInsertRows(). The view is updated as expected.

    What works with the "proxy part":

    The same data is displayed, through a QAbstractProxyModel, in another QTableView.

    The re-mapping of indexes and selections is implemented and data is displayed correctly.

    What does not work:

    The view linked to the data via the proxy model is not updated if I change/add data to the model.

    The re-mapping of model indexes is relatively complex, and it is not trivial to determine which table fields will change in the "proxy view" when the original model is changed. Therefore, it would be great just to tell the view/proxy model to re-read all (visible) table fields, and to display more/less rows/columns if necessary. However, I unfortunately could not figure out how to do that.

    Do I miss an important underlying concept here?

    Thanks for your help

    Pascal

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Proxy model / view update problem

    Is your model emitting the dataChanged and other signals correctly?

  3. #3
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Proxy model / view update problem

    Try using the beginResetModel and endResetModel calls before and after (respectively) modifying data in the model.

  4. #4
    Join Date
    Apr 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Proxy model / view update problem

    Re the signals: I think they are emitted correctly, since the view linked directly to the model is updated correctly. (I emit dataChanged() and use beginInsertRows() etc).

    What I don't understand is what the proxy model is supposed to handle automatically. I use QAbstractProxyModel, but it is not clear to me what happens with the signals (e.g. dataChanged in the original models). Do I have to somehow translate these by mapping the Indexes to the new layout? What signals need to be connected? If yes, this will probably be very difficult, since data insertion in the original model will change the data in the 2nd view in a non-trivial way. Re-reading the displayed fields would therefore be easiest.

    @stefanadelbert: beginResetModel() is only part of qt4.6, and I am using 4.5 for the moment. Is there a way to "emulate" this behaviour in the meanwhile?

  5. #5
    Join Date
    Feb 2010
    Location
    Sydney, Australia
    Posts
    111
    Thanks
    18
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Proxy model / view update problem

    I'm afraid that I don't know of a way to emulate the begin- and endResetModel signals. I only started using Qt at 4.6.2, so Qt4.6 is all I know! You know have your model emit a custom signal and have a derived QTableView handle the signal and do what it needs to do, which could be explicitely reloading its data somehow. I'm looking at QAssistant now though and there isn't an obvious way yo get a QTableView to reload its data.

    Edit: Take a look at the post entitled "How to notify QTableView of a modified CustomModel". There could be a solution for you there.

Similar Threads

  1. Replies: 1
    Last Post: 18th November 2009, 23:21
  2. how to update a tree view model
    By chow in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 15:27
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Replies: 9
    Last Post: 7th November 2006, 15:10
  5. Filter Proxy Model to Autoupdate View
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2006, 20:32

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.