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. QTreeView - Add child (append rows) on expand
Forum Update on Monday, May 27th 2025

QTreeView - Add child (append rows) on expand

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.3k Views
  • 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.
  • K Offline
    K Offline
    kumararajas
    wrote on last edited by
    #1

    Hello,

    I want to append the rows on expand. Meaning, I want to have the "+" sign enabled even if there are no rows present below. Because, I will be adding the rows on expand.

    How to achieve this?

    Thanks,
    Kumar

    --Kumar

    raven-worxR 1 Reply Last reply
    0
    • K kumararajas

      Hello,

      I want to append the rows on expand. Meaning, I want to have the "+" sign enabled even if there are no rows present below. Because, I will be adding the rows on expand.

      How to achieve this?

      Thanks,
      Kumar

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

      @kumararajas
      override QAbstractItemModel::canFetchMore() and return true when there is data available for loading, false otherwise.

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

      K 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @kumararajas
        override QAbstractItemModel::canFetchMore() and return true when there is data available for loading, false otherwise.

        K Offline
        K Offline
        kumararajas
        wrote on last edited by
        #3

        @raven-worx

        It is new to me. Thanks for the thought Raven.
        But, still I am unable to get the expected results.

        I have overridden canFetchMore and return true always.

        bool MyClass::canFetchMore(const QModelIndex & parent) const
        {
            return true;
        }
        

        But, if I do not appendRow, then, I do not see the "expand" sign.

        Since I dont see the "expand" sign, I am unable to load the items.

        My goal is to load the items only on expand.

        Any thoughts?

        Thanks,
        Kumara

        --Kumar

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kumararajas
          wrote on last edited by
          #4

          This is classic!

          I was doing some silly mistakes. And I was too quick to reply back.

          Later fixing my bugs, I could achieve it.

          Thank you very much Raven!

          --Kumara

          --Kumar

          raven-worxR 1 Reply Last reply
          0
          • K kumararajas

            This is classic!

            I was doing some silly mistakes. And I was too quick to reply back.

            Later fixing my bugs, I could achieve it.

            Thank you very much Raven!

            --Kumara

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

            @kumararajas
            and btw. what i forgot to mention:
            you should load your data in the fetchMore() method of the model. IIRC this is called by the treeview on expand (when canFetchMore() returns true for this index). Maybe also in some other situations by Qt.
            Anyway it's always a good idea to follow the given API.

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

            K 1 Reply Last reply
            0
            • raven-worxR raven-worx

              @kumararajas
              and btw. what i forgot to mention:
              you should load your data in the fetchMore() method of the model. IIRC this is called by the treeview on expand (when canFetchMore() returns true for this index). Maybe also in some other situations by Qt.
              Anyway it's always a good idea to follow the given API.

              K Offline
              K Offline
              kumararajas
              wrote on last edited by
              #6

              @raven-worx Thanks Raven! That helps me a lot..

              --Kumar

              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