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. [SOLVED]QTreeView - removing a row
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QTreeView - removing a row

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 7.1k 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.
  • D Offline
    D Offline
    Dolphin
    wrote on last edited by
    #1

    I have a simplified version of my code below which gives me 4 top level rows each containing 4 rows. The problem is how to delete the inner rows? Nothing I have tried will remove an "AA" row and some of the options will not remove any "One" rows either. It seems like this should be obvious but no joy!

    @ for(int row(0); row < 4; row++)
    {
    QStandardItem* parent = new QStandardItem("One");
    m_model->appendRow(parent);

    for(int row2(0); row2 < 4; row2++)
    {
    QStandardItem* item = new QStandardItem("AA");
    parent->appendRow(item);
    }
    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dolphin
      wrote on last edited by
      #2

      @ QModelIndex index = m_view->currentIndex();
      if(index.isValid())
      {
      CMenuTreeRow *current = (CMenuTreeRow *) m_model->itemFromIndex(index);
      if(current)
      {
      int currentRow = current->row();
      CMenuTreeRow *parent = (CMenuTreeRow *) current->parent();
      if(parent)//we are at top of tree - do not delete!
      {
      QModelIndex parentIndex = parent->index();

      m_model->removeRow(currentRow, parentIndex);
      

      }
      }
      }
      @

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi guys,
        Don't forget the startDeleteRows() functions!! The view/model might crash otherwise.
        greetz

        Greetz, Jeroen

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dolphin
          wrote on last edited by
          #4

          OK, thanks :-)

          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