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 to get the index of a TreeItem in a TreeModel
Forum Updated to NodeBB v4.3 + New Features

How to get the index of a TreeItem in a TreeModel

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 607 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.
  • I Offline
    I Offline
    Infinity
    wrote on last edited by
    #1

    I have a treeModel based on this example:

    https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/editabletreemodel

    I would like to delete a specific item in the tree model, but this item is not selected. How can I get the index of a treeItem?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So how to do you know what item you want to delete?
      See https://doc.qt.io/qt-5/model-view-programming.html#model-classes on how to get an index to an item

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        If you just want to delete a certain row/column than you can use
        QAbstractItemModel::index(int row, int column)
        https://doc.qt.io/qt-5/qabstractitemmodel.html#index

        However be sure to call beginRemoveRows() and endRemoveRows() when you're deleting it.

        Christian EhrlicherC 1 Reply Last reply
        0
        • gde23G gde23

          If you just want to delete a certain row/column than you can use
          QAbstractItemModel::index(int row, int column)
          https://doc.qt.io/qt-5/qabstractitemmodel.html#index

          However be sure to call beginRemoveRows() and endRemoveRows() when you're deleting it.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @gde23 It's a tree - the parent is important. Therefore my question...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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