Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add dynamically new item in gridView
Qt 6.11 is out! See what's new in the release blog

Add dynamically new item in gridView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.8k 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.
  • S Offline
    S Offline
    Salydan
    wrote on last edited by
    #1

    Hi everyone,

    I would like to know if it's possible to add a new item in a gridView when the user click on a button for example. I see nothing about that on internet.

    On the screen below you can see my gridView. Currently I add items with the "listElement"
    Sample code grid View

    Thanks a lot

    Have a good day
    Simon

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #2

      Since you are using the model view frame with GridView, Model and Delegate, just add new element to the model. Grid View will be updated automatically with new delegate. No extra effort!!!!

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      S 1 Reply Last reply
      2
      • dheerendraD dheerendra

        Since you are using the model view frame with GridView, Model and Delegate, just add new element to the model. Grid View will be updated automatically with new delegate. No extra effort!!!!

        S Offline
        S Offline
        Salydan
        wrote on last edited by
        #3

        @dheerendra said in Add dynamically new item in gridView:

        Since you are using the model view frame with GridView, Model and Delegate, just add new element to the model. Grid View will be updated automatically with new delegate. No extra effort!!!!

        Can you show me sample code to add in my "button.onClicked" function to do this ?

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
          wrote on last edited by
          #4

          You can do something like follows in button.onClicked handler.

          gridView.model.insert(...) or gridView.model.append(..).

          See the ListModel documentation for the insert and/or append documentation. It should help you.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          https://www.pthinks.com

          S 1 Reply Last reply
          2
          • dheerendraD dheerendra

            You can do something like follows in button.onClicked handler.

            gridView.model.insert(...) or gridView.model.append(..).

            See the ListModel documentation for the insert and/or append documentation. It should help you.

            S Offline
            S Offline
            Salydan
            wrote on last edited by
            #5

            @dheerendra said in Add dynamically new item in gridView:

            ListModel

            Thanks a lot !
            Its work perfectly :)

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
              wrote on last edited by
              #6

              Cool. Make the issue to "Solved". It helps others.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              https://www.pthinks.com

              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