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 update QTreeView?
Qt 6.11 is out! See what's new in the release blog

How to update QTreeView?

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 4.3k 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.
  • JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #6

    @ahsan737 , @Mucip
    Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

    J.HilkJ MucipM 2 Replies Last reply
    0
    • JonBJ JonB

      @ahsan737 , @Mucip
      Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #7

      @JonB

      I think the OP did not use a proper model but rather the (in)famous setItemWidget function...


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      JonBJ ahsan737A 2 Replies Last reply
      0
      • J.HilkJ J.Hilk

        @JonB

        I think the OP did not use a proper model but rather the (in)famous setItemWidget function...

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #8

        @J-Hilk
        @ahsan737 wrote:

        I am building the QTreeView model from CSV data,

        Clearly your powers of guessing/interpreting are better than mine! ;)

        1 Reply Last reply
        0
        • JonBJ JonB

          @ahsan737 , @Mucip
          Sorry, I don't understand these two posts. If your QTreeView is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is no QTreeView::clear()? Obviously "regenerate the model" does not mean "append to whatever is presently there".

          MucipM Offline
          MucipM Offline
          Mucip
          wrote on last edited by
          #9

          @JonB ,
          I mean;
          ui->someTreeWidget->clear();

          Regards,
          Mucip:)

          JonBJ 1 Reply Last reply
          0
          • MucipM Mucip

            @JonB ,
            I mean;
            ui->someTreeWidget->clear();

            Regards,
            Mucip:)

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #10

            @Mucip
            OK, but that is QTreeWidget::clear(), and the OP's question is "How to update QTreeView", QTreeWidget has never been mentioned. I'm sure he would ask about QTreeWidget not just QTreeView if that's what he wants to know about. Ho-hum.

            1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @JonB

              I think the OP did not use a proper model but rather the (in)famous setItemWidget function...

              ahsan737A Offline
              ahsan737A Offline
              ahsan737
              wrote on last edited by
              #11

              @J-Hilk I am creating the QTreeView model using this method:

              //--------------------Tree View Model--------------------------
              QStandardItemModel *model=new QStandardItemModel (this);
              rootItem=model->invisibleRootItem();
              
              QStandardItem *TitleItem=new QStandardItem ("\n"+Title_line.at(i)+"\n"+second_line.at(i)+"\n"+third_line.at(i));
              
              TitleItem->setIcon(QIcon(":/img/img/saved_data.jpg.png"));
              
              //defining tree structure
              rootItem->appendRow(TitleItem);
              ui->treeView->setModel(model);
              
              JonBJ 1 Reply Last reply
              0
              • ahsan737A ahsan737

                @J-Hilk I am creating the QTreeView model using this method:

                //--------------------Tree View Model--------------------------
                QStandardItemModel *model=new QStandardItemModel (this);
                rootItem=model->invisibleRootItem();
                
                QStandardItem *TitleItem=new QStandardItem ("\n"+Title_line.at(i)+"\n"+second_line.at(i)+"\n"+third_line.at(i));
                
                TitleItem->setIcon(QIcon(":/img/img/saved_data.jpg.png"));
                
                //defining tree structure
                rootItem->appendRow(TitleItem);
                ui->treeView->setModel(model);
                
                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #12

                @ahsan737
                I did say earlier to answer both your questions:

                @ahsan737
                If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.
                .
                You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

                You said:

                @JonB if I regenerate then it doubles the information.

                But it should not do that. So what did you do?

                ahsan737A 1 Reply Last reply
                0
                • JonBJ JonB

                  @ahsan737
                  I did say earlier to answer both your questions:

                  @ahsan737
                  If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.
                  .
                  You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.

                  You said:

                  @JonB if I regenerate then it doubles the information.

                  But it should not do that. So what did you do?

                  ahsan737A Offline
                  ahsan737A Offline
                  ahsan737
                  wrote on last edited by
                  #13

                  @JonB thank you for the considerate response, can you please help with a sample code then it will be easy for me to understand, I am not good with Qt.

                  JonBJ 1 Reply Last reply
                  0
                  • ahsan737A ahsan737

                    @JonB thank you for the considerate response, can you please help with a sample code then it will be easy for me to understand, I am not good with Qt.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #14

                    @ahsan737
                    You should show what code you have used to "regenerate then it doubles the information".

                    ahsan737A 2 Replies Last reply
                    2
                    • JonBJ JonB

                      @ahsan737
                      You should show what code you have used to "regenerate then it doubles the information".

                      ahsan737A Offline
                      ahsan737A Offline
                      ahsan737
                      wrote on last edited by
                      #15
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @ahsan737
                        You should show what code you have used to "regenerate then it doubles the information".

                        ahsan737A Offline
                        ahsan737A Offline
                        ahsan737
                        wrote on last edited by
                        #16

                        @JonB I have done that successfully, thank you for guidance. I was only clearing model and rootItem data but forgot to reset variable values.

                        JonBJ 1 Reply Last reply
                        0
                        • ahsan737A ahsan737

                          @JonB I have done that successfully, thank you for guidance. I was only clearing model and rootItem data but forgot to reset variable values.

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by
                          #17

                          @ahsan737
                          This is why it's always good to show code :)

                          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