Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QModelIndex: Get for same column in parent?
QtWS25 Last Chance

QModelIndex: Get for same column in parent?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nonot1
    wrote on last edited by
    #1

    Hello,

    I'm working with the sample code at:
    http://doc.qt.nokia.com/latest/itemviews-simpletreemodel.html

    Given a QModelIndex pointing at a certain item, how do I get a QModelIndex for the item's parent that points to the same column?

    Just calling someIndex.parent() will always return a QModelIndex with column == 0.

    In this sample case, since each row has the same number of columns, so we know for sure that every parent (other than the invisible root) certainly has such a column.

    What is the correct method?

    Thank you

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You could do something like this:

      @
      QModelIndex parent = someIndex.parent();
      QModelIndex parentColumn = someIndex.model().index(parent.parent(), parent.row(), someIndex.column());
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved