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. Perform an action when a repeater is done updating a component

Perform an action when a repeater is done updating a component

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 541 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.
  • L Offline
    L Offline
    lagarkane
    wrote on last edited by
    #1

    Hi there,

    I have a QML Menu that is filled with MenuItems through a repeater.
    I would like to be able to add in that same menu, after the repeater's entries, a MenuSeparator, followed by other MenuItems, but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.

    My current code looks like this:

            Menu {
                id: menu
                title: "Open recent"
                enabled: recentsList.length
    
                property var recentsModel: ListModel { id: mModel }
                property var modelList: recentsList
                onModelListChanged: {
                    mModel.clear()
                    for (var i = 0 ; i < modelList.length ; i++)
                        mModel.append({"index": i, "title": modelList[i], "fileUrl": modelList[i]})
                }
    
                Repeater {
                    model: mModel
                    MenuItem {
                        text: model.title
                        onTriggered: {
                            // doSomething
                        }
                    }
                }
                MenuSeparator { visible: menu.enabled }
                MenuItem {
                    text: "Clear Recents"
                    onTriggered: recentsList.clear()
                }
            }
    

    This code works, until my model changes, in which case the repeater removes the old items from the view, and appens them back, after my separator and my "Clear Recents" MenuItem.

    I searched for a signal maybe, from the repeater that would tell me when he's done updating the view, but I didn't find anything like that.

    Is it possible to guarantee that my elements are added After the repeater has updated the view from the model?

    Thanks in advance for your kind answers!

    ODБOïO 1 Reply Last reply
    0
    • L lagarkane

      Hi there,

      I have a QML Menu that is filled with MenuItems through a repeater.
      I would like to be able to add in that same menu, after the repeater's entries, a MenuSeparator, followed by other MenuItems, but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.

      My current code looks like this:

              Menu {
                  id: menu
                  title: "Open recent"
                  enabled: recentsList.length
      
                  property var recentsModel: ListModel { id: mModel }
                  property var modelList: recentsList
                  onModelListChanged: {
                      mModel.clear()
                      for (var i = 0 ; i < modelList.length ; i++)
                          mModel.append({"index": i, "title": modelList[i], "fileUrl": modelList[i]})
                  }
      
                  Repeater {
                      model: mModel
                      MenuItem {
                          text: model.title
                          onTriggered: {
                              // doSomething
                          }
                      }
                  }
                  MenuSeparator { visible: menu.enabled }
                  MenuItem {
                      text: "Clear Recents"
                      onTriggered: recentsList.clear()
                  }
              }
      

      This code works, until my model changes, in which case the repeater removes the old items from the view, and appens them back, after my separator and my "Clear Recents" MenuItem.

      I searched for a signal maybe, from the repeater that would tell me when he's done updating the view, but I didn't find anything like that.

      Is it possible to guarantee that my elements are added After the repeater has updated the view from the model?

      Thanks in advance for your kind answers!

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      Hi
      @lagarkane said in Perform an action when a repeater is done updating a component:

      but I want those new items to always show up after the ones added by the repeater, even if the model changes at some point.

      you can use Qt Quick Layouts to handle that

      ColumnLayout{
          spacing: 2
      
          Item{
            Repeater {
                      model: mModel
                      MenuItem {
                          text: model.title
                          onTriggered: {
                              // doSomething
                          }
                      }
                  }
          }
      
          MenuSeparator {}
      
          MenuItem {}
      }
      
      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