Results 1 to 4 of 4

Thread: [qt4,win,g++] qpersistentmodelindex - qmodelindex

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [qt4,win,g++] qpersistentmodelindex - qmodelindex

    hi,

    i have a model which is displayed by a treeview. the model subclasses
    QAbstractItemModel.
    using a selection model i can delegate the selection from the view to the
    model. but how do i delegate the selection from the model to the view?
    to call select() (QItemSelection) i need a modelindex. to get a modelindex
    i need a row, a column and a parent which i do not have,
    traversing the model to get these is to time consuming. i thought about
    storing a persistent model index for each item but this sounds memory
    consuming to me a i suppose there are better ways.
    any hints?

    best regards,
    jh

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

    Default Re: [qt4,win,g++] qpersistentmodelindex - qmodelindex

    Could you say what do you need it for? In general, the selection is an attribute of a view. The model just holds the data. You shouldn't keep the selection in the data model.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4,win,g++] qpersistentmodelindex - qmodelindex

    I have a model which contains geometric elements such as solids,
    lines, text, triangles and more. These elements are in containers so i get a
    hierarchy. The elements can be selected by clicking
    in a graphical representation (using OpenGL) but also clicking on an item in a tree view.
    If the user selects an element in the treeview the OpenGL view should show the
    element selected and vice versa. I have model items which represents the
    model (each item got a pointer to an graphical element). These model items
    are stored as internal pointers in a QModelIndex. If any item is selected in the
    tree i get some QModelIndex, access the items by calling internalPointer() and
    can delegate the selection to the OpenGL view. If the user selects in the OpenGL
    view it's more diffucult. I get the model items but have to indices (row,column,parent)
    to create a QModelIndex which i can pass to the selection model. My solution would be
    to store for each model item a persistent model index (QPersistentModelIndex)
    but this it not very efficient since i have to store the core item, the model item
    plus the persistent model index.

    In qt3 i created a subclass of treeviewitems which stored a pointer to the
    graphics element. If the selection changed or the user clicked on an item this item
    was passed as an argument to the accordant slots. So it was very easy to change the
    selection in any other view.

    Any ideas to solve this problem?

    best regards,
    jh

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

    Default Re: [qt4,win,g++] qpersistentmodelindex - qmodelindex

    Use a persistant model index. It's the simplest solution. Otherwise you'd have to map view coordinates to model item indices.

Similar Threads

  1. QAbstractProxyModel to do a Tree
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2008, 17:31
  2. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 18:14
  3. Problem with TreeView
    By init2null in forum Qt Programming
    Replies: 8
    Last Post: 25th May 2008, 09:56
  4. QAbstractItemModel newbie question
    By okellogg in forum Qt Programming
    Replies: 14
    Last Post: 18th February 2008, 12:30
  5. Replies: 6
    Last Post: 21st September 2007, 13:51

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.