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. I am getting an extra row and can some one correct my code
Forum Updated to NodeBB v4.3 + New Features

I am getting an extra row and can some one correct my code

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 330 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by VRonin
    #1
    void myWidget::createTree() 
    {
      QAbstractItemModel* const mdl = m_tree->model();
      mdl->removeRows(0,mdl->rowCount());
      mdl->removeColumns(0,mdl->columnCount());
      mdl->insertRows(0,2);
           
      QModelIndex tempIdx; 
      QModelIndex top1Idx = tempIdx = mdl->index(0,0);
      mdl->insertRow(0,tempIdx);
      tempIdx = mdl->index(0,0);
      mdl->setData(tempIdx,"A");
      mdl->setData(tempIdx,m_stacked->addWidget(mapWidgetNameToTextBrowser["A"]),Qt::UserRole);
            
      QModelIndex top2Idx = tempIdx  = mdl->index(1,0);
      mdl->insertRow(0,tempIdx);
      tempIdx = mdl->index(1,0);
      mdl->setData(tempIdx,"B");
      mdl->setData(tempIdx,m_stacked->addWidget(mapWidgetNameToTextBrowser["B"]),Qt::UserRole);
    
    
            ////////////////////////////////////////
            ///////////////////////////////////////////
     
    
       tempIdx = top1Idx;
       mdl->insertRow(0,tempIdx);
       QModelIndex currentParentIdx = tempIdx = mdl->index(0,0,tempIdx);
       mdl->setData(tempIdx,"C");
       mdl->setData(tempIdx,m_stacked->addWidget(mapWidgetNameToTextBrowser["C"]),Qt::UserRole);
    
       //mdl->insertRow(0,currentParentIdx);
       tempIdx = mdl->index(0,0,currentParentIdx);
       mdl->setData(tempIdx,"D");
       mdl->setData(tempIdx,m_stacked->addWidget(mapWidgetNameToTextBrowser["D"]),Qt::UserRole);
    

    A
    ----C
    -------D
    ----------- ---------------> extra row
    B

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

      It's not clear from the drawing who's the parent of the extra row

      "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
      1

      • Login

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