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. How can I get a parent from child in treeView?
Forum Updated to NodeBB v4.3 + New Features

How can I get a parent from child in treeView?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 364 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I wrote:

    const QModelIndex index1 = ui->treeView_7->selectionModel()->currentIndex();

    int w= index1.row()+1;
    

    but If I select a child I want to get the parent of selected child

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      It might blow your mind:

      QModelIndex index1 = ui->treeView_7->selectionModel()->currentIndex();
      QModelIndex index2 = index1.parent();
      

      https://doc.qt.io/qt-5/qmodelindex.html#parent

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ? 1 Reply Last reply
      2
      • VRoninV VRonin

        It might blow your mind:

        QModelIndex index1 = ui->treeView_7->selectionModel()->currentIndex();
        QModelIndex index2 = index1.parent();
        

        https://doc.qt.io/qt-5/qmodelindex.html#parent

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @VRonin thanks..it works

        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