Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get QModelIndex from TreeView rowDelegate
Forum Updated to NodeBB v4.3 + New Features

Get QModelIndex from TreeView rowDelegate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 843 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.
  • ProgSysP Offline
    ProgSysP Offline
    ProgSys
    wrote on last edited by
    #1

    Hi,
    I have a cutom rowDelegate for a treeview and I need to access it's QModelIndex. So I can implement custom expand and collapse methods. The problem is, only styleData.row seams to be provided and I dont know how to convert it into a QModelIndex.

    I found an old topic about this, but it's sadly unresolved: Get QModelIndex from Treeview rowDelegate
    styleData.row is relative to the root item, so unless you know the number of previous displayed sub items you can't calculate the index:

    + Item A // styleData.row 0
    - Item B // styleData.row 1
        * Sub Item A // styleData.row 2 (Expected 0)
        * Sub Item B // styleData.row 3 (Expected 1)
    + Item C // styleData.row 4 (Expected 2)
    

    Thanks!

    E 1 Reply Last reply
    0
    • ProgSysP ProgSys

      Hi,
      I have a cutom rowDelegate for a treeview and I need to access it's QModelIndex. So I can implement custom expand and collapse methods. The problem is, only styleData.row seams to be provided and I dont know how to convert it into a QModelIndex.

      I found an old topic about this, but it's sadly unresolved: Get QModelIndex from Treeview rowDelegate
      styleData.row is relative to the root item, so unless you know the number of previous displayed sub items you can't calculate the index:

      + Item A // styleData.row 0
      - Item B // styleData.row 1
          * Sub Item A // styleData.row 2 (Expected 0)
          * Sub Item B // styleData.row 3 (Expected 1)
      + Item C // styleData.row 4 (Expected 2)
      

      Thanks!

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @ProgSys I haven't used Controls 1 but the TreeViewStyle documentation tells that branchDelegate has access to

      styleData.index - the QModelIndex of the current item in the model
      

      Does it help?

      1 Reply Last reply
      0
      • ProgSysP Offline
        ProgSysP Offline
        ProgSys
        wrote on last edited by
        #3

        branchDelegate indeed has 'styleData.index', but I can't get it to cover the entire row and if I use QSortFilterProxyModel to sort and filter my model the value is wrong.

        1 Reply Last reply
        1

        • Login

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