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



  • 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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.