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 having sequence problem

I am having sequence problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 630 Views 2 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

    Following sthe post https://forum.qt.io/topic/85736/looking-for-a-sample-example-in-which-qtreewidget-at-left-side-qsplitter-and-qstackedwidget-on-right-side/3

    One more question regarding the sequnce of displayed children

       QModelIndex tempIdx  = mdl->index(0,0);
        mdl->setData(tempIdx,"Parent1");
        mdl->setData(tempIdx,m_stacked->addWidget(QLabel("A"),Qt::UserRole);
        ////////////////////////////////////////
        ///////////////////////////////////////////
        tempIdx = mdl->index(0,0,tempIdx);
        mdl->setData(tempIdx,"Child1");
        mdl->setData(tempIdx,m_stacked->addWidget(new QTextEdit("Child1",this)),Qt::UserRole);
    
    
        mdl->insertRow(0,tempIdx);
        QModelIndex tempIdx = mdl->index(0,0,tempIdx);
        mdl->setData(tempIdx,"ChildOfChidl1");
        QTableWidget* tempTable1 = new QTableWidget(2,2,this);
        tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildOfChild1 Cell 0,0");
        tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildOfChild1 Cell" ,0");
        mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
    
        mdl->insertRow(0,tempIdx);
        QModelIndex tempIdx = mdl->index(0,0,tempIdx);
        mdl->setData(tempIdx,"ChildAOfChidl1");
        QTableWidget* tempTable1 = new QTableWidget(2,2,this);
        tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildOfChild1 Cell 0,0");
        tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildOfChild1 Cell" ,0");
        mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
    
       mdl->insertRow(0,tempIdx);
        QModelIndex tempIdx = mdl->index(0,0,tempIdx);
        mdl->setData(tempIdx,"ChildBOfChidl1");
        QTableWidget* tempTable1 = new QTableWidget(2,2,this);
        tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildBOfChild1 Cell 0,0");
        tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildBOfChild1 Cell" ,0");
        mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
    

    In my case sequence is a issue ChildBOfChild1 is displayed before ChildAOfChild1 why ?

    [Added code tags ~kshegunov]

    raven-worxR 1 Reply Last reply
    0
    • Q Qt Enthusiast

      Following sthe post https://forum.qt.io/topic/85736/looking-for-a-sample-example-in-which-qtreewidget-at-left-side-qsplitter-and-qstackedwidget-on-right-side/3

      One more question regarding the sequnce of displayed children

         QModelIndex tempIdx  = mdl->index(0,0);
          mdl->setData(tempIdx,"Parent1");
          mdl->setData(tempIdx,m_stacked->addWidget(QLabel("A"),Qt::UserRole);
          ////////////////////////////////////////
          ///////////////////////////////////////////
          tempIdx = mdl->index(0,0,tempIdx);
          mdl->setData(tempIdx,"Child1");
          mdl->setData(tempIdx,m_stacked->addWidget(new QTextEdit("Child1",this)),Qt::UserRole);
      
      
          mdl->insertRow(0,tempIdx);
          QModelIndex tempIdx = mdl->index(0,0,tempIdx);
          mdl->setData(tempIdx,"ChildOfChidl1");
          QTableWidget* tempTable1 = new QTableWidget(2,2,this);
          tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildOfChild1 Cell 0,0");
          tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildOfChild1 Cell" ,0");
          mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
      
          mdl->insertRow(0,tempIdx);
          QModelIndex tempIdx = mdl->index(0,0,tempIdx);
          mdl->setData(tempIdx,"ChildAOfChidl1");
          QTableWidget* tempTable1 = new QTableWidget(2,2,this);
          tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildOfChild1 Cell 0,0");
          tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildOfChild1 Cell" ,0");
          mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
      
         mdl->insertRow(0,tempIdx);
          QModelIndex tempIdx = mdl->index(0,0,tempIdx);
          mdl->setData(tempIdx,"ChildBOfChidl1");
          QTableWidget* tempTable1 = new QTableWidget(2,2,this);
          tempTable1->model()->setData(tempTable1->model()->index(0,0),"ChildBOfChild1 Cell 0,0");
          tempTable1->model()->setData(tempTable1->model()->index(1,0),"ChildBOfChild1 Cell" ,0");
          mdl->setData(tempIdx,m_stacked->addWidget(tempTable1),Qt::UserRole);
      

      In my case sequence is a issue ChildBOfChild1 is displayed before ChildAOfChild1 why ?

      [Added code tags ~kshegunov]

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Qt-Enthusiast said in I am having sequence problem:

      mdl->insertRow(0,tempIdx);
      QModelIndex tempIdx = mdl->index(0,0,tempIdx);

      1. you are always inserting at position 0
      2. you are overwriting/redefine the tempIdx variable multiple times

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      4
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        replace

        mdl->insertRow(0,tempIdx);
            QModelIndex tempIdx = mdl->index(0,0,tempIdx);
        

        with

        const int rowCnt = mdl->rowCount(tempIdx);
        mdl->insertRow(rowCnt ,tempIdx);
        tempIdx = mdl->index(rowCnt ,0,tempIdx);
        

        to insert at the bottom instead of at the top

        "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

        • Login

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