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. Getting very confused trying to get all children of a selected thingy in a QTreeView

Getting very confused trying to get all children of a selected thingy in a QTreeView

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 611 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by
    #1

    I have a QTreeView. It shows a hierarchy of files in directories.

    When the user selects something that has children (i.e. a directory) I want to automatically select all the children. I get the index of the selected directory like this:

    @ QModelIndexList selectedIndices = ui->projectExplorerTreeView->selectionModel()->selectedIndexes();@

    That actually gives me four indices (supposing only one line in the QTreeView is selected). The first column (i.e. column number zero) is the one that has children, judging by the picture in my QTreeView window.

    I yomp through all the selected indices like this (one of them is my little directory picture with children, the other indices are other columns

    @ for (int i = 0; i<selectedIndices.size(); ++i)
    {
    if (selectedIndices.at(i).column() == 0) // this one is the one that might have children
    {
    // Get index value of all children
    }
    }@

    I was expecting to be able to interrogate any given index to ask it for its children. I see the function @QModelIndex QModelIndex::child ( int row, int column ) const@
    which says it "Returns the child of the model index that is stored in the given row and column."

    But if I knew which row and column in the model contained a child, I wouldn't need this function. I must be misunderstanding this. Is this how I'm meant to get the children of a given index?

    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