Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business


OverviewFelgo 3 Support (Qt 5) › Edit json property in JsonListModel

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #23470


    Hey Guys!
    I’m currently trying to adjust a value of some data in my JsonModel from true/false, the information isn’t downloaded from a webserver or anything, it’s hardcoded into my application, what i’m trying to do is create a drop-down list using, the JsonListModel;

    I have tried working with the jsonModel.set() or jsonModel.setPropertys() – neither error, and both log the corrent change, but dont update the entry, i’m not looking at adding a new property – simply changing a Boolean within; working with a previous ‘dropdown’ list tutorial I have so far:

    What I am looking to do, is change the ‘jsonData’ property from true/false when I send the signal (when I console.log my current signal, It is ‘flicking the switch’ so to speak, but not updating my JSON – how could I go about this?

    I further want the ‘height’ property to naturally be adjusted dependant on the ‘content’ of the row, is there a way I can access ‘contentHeight’ of my simpleRow delegate?
    Code below!


    Page {
        id: faqPage
        property bool expanded: false
        property var currIndex
        JsonListModel {
            id: jsonModel
            source: faqPage.jsonData
            keyField: "id"
            fields: ["id", "title", "content", "avisible"]
        SortFilterProxyModel {
        id: sortedModel
        Component.onCompleted: sourceModel = jsonModel
        sorters: StringSorter { id: typeSorter; roleName:              "title"; ascendingOrder: true }
        AppListView {
        id: listView
        anchors.fill: parent
        property string expandedSection: ""
        model: sortedModel
        delegate: SimpleRow {
            id: rowDelegate
            visible: model.avisible
            onVisibleChanged: {
                (listView.currentIndex = currIndex) ===   currIndex
                 height = dp(350)
                 height = 0
            section.property: "title"
            section.delegate: SimpleSection {
                id: sectionHeadRect
                property bool isExpanded: false
                property string currentExpandedSection:               ListView.view.expandedSection
                onCurrentExpandedSectionChanged: {
                    if(currentExpandedSection === section) {
                        isExpanded = true
                    } else {
                        isExpanded = false
              onIsExpandedChanged: {
                      expanded = true
                      ListView.view.expandedSection = section;
                  } else
                      expanded = false
                      for(var i=0; i<jsonModel.count; i++){
                          var animal = jsonModel.get(i);
                          if(title === animal.title)
                              animal.aVisible = sectionHeadRect.isExpanded;
                     onSelected: {
                        currIndex = jsonModel.indexOf("title",  title)
                        sectionHeadRect.isExpanded = ! sectionHeadRect.isExpanded;
                    enabled: true
            property var jsonData: [
    "id": 1,
    "title": "title 1",
    "content": "cont1",
    "avisible": false
    "id": 2,
    "title": "title2",
    "content": "cont2",
    "avisible": false
    "id": 3,
    "title": "title3",
    "content": "cont3",
    "avisible": false







    Yeah I’ve figured it out – I was being foolish with where I was trying to adjust data, so when my ‘section’ is selected I simply;

    onSelected: {
                   currIndex = jsonModel.indexOf("title", title)
                   jsonData[currIndex].avisible === true ? jsonData[currIndex].avisible = false : jsonData[currIndex].avisible = true
                   sectionHeadRect.isExpanded = !sectionHeadRect.isExpanded;

    and it works as intended!


    Now I simple need to make the height of each listView.delegate dynamic depending on the length of the content……

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded