Results 1 to 2 of 2

Thread: Mapping Index from View to Model

  1. #1
    Join Date
    Jun 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Mapping Index from View to Model

    I have a subclass called TableModel that is derived from QAbstractTableModel and the TableModel is fed into a QSortFilterProxyModel... and this is fed into a QTableView. Let's say I use match() in the QSortFilterProxyModel to find some data in the view and in return I get a QModelIndex of the cell. Also, my TableModel contains a QMap of an int that is mapped to a Trace*.

    My question is : how do I use this QModelIndex from the view/proxy to get back to the Trace entry in TableModel? I have the cell location in the proxy but I want to get other hidden information about the entry in the model.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Mapping Index from View to Model

    First of all you should never access that internal structure directly. You should expose all the data you need using QAbstractItemModel API (choosing to wrap your structure (but not a pointer to it) into QVariant as last choice). If you want to map indices between models, use QAbstractProxyModel::mapToSource().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Proxy model, index mapping.
    By wojtekw in forum Qt Programming
    Replies: 14
    Last Post: 7th January 2016, 08:09
  2. Replies: 4
    Last Post: 18th April 2012, 18:11
  3. Replies: 1
    Last Post: 1st February 2010, 18:42
  4. Model/View one index.column as hidden UserRole
    By doitux in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2008, 12:08
  5. Replies: 1
    Last Post: 13th June 2008, 18:58

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
  •  
Qt is a trademark of The Qt Company.