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. Remove a ListElement from the ListView without removing it from the model
Forum Updated to NodeBB v4.3 + New Features

Remove a ListElement from the ListView without removing it from the model

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 503 Views 1 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.
  • D Offline
    D Offline
    DavidM29
    wrote on last edited by DavidM29
    #1

    Hello,

    I do have a list of component. That list is defined by a JS Model.
    I would like to handle the visibilty of some elements without removing the elements from the model.

    I fact I do save some param via the index of the model and if I remove it it will make all my saving function obselete.

    Here is an example of what if have :

    property var model:
        [
           {"type": "switch", "optionName": qsTr("Option 1")+trans.emptyString, "value" : option1Value},
           {"type": "switch", "optionName": qsTr("Option 2")+trans.emptyString, "value" : option2Value},
           {"type": "input", "optionName": qsTr("Option 3")+trans.emptyString, "value": option3Value}
        ]
    
    ListView {
                id: dataView
                clip: true
                spacing : 2
                model: window.model
                delegate: OptionDelegate{}
                interactive: false
            }
    

    What I have tried is that I use a property in my model called visibilty for example. And I use this property in order to change the visible property of my delegate. It work I don't see my delegate anymore but it leave a blank in the list and I don't want that.

    Is there anyway to handle this ?

    ODБOïO 1 Reply Last reply
    0
    • D DavidM29

      Hello,

      I do have a list of component. That list is defined by a JS Model.
      I would like to handle the visibilty of some elements without removing the elements from the model.

      I fact I do save some param via the index of the model and if I remove it it will make all my saving function obselete.

      Here is an example of what if have :

      property var model:
          [
             {"type": "switch", "optionName": qsTr("Option 1")+trans.emptyString, "value" : option1Value},
             {"type": "switch", "optionName": qsTr("Option 2")+trans.emptyString, "value" : option2Value},
             {"type": "input", "optionName": qsTr("Option 3")+trans.emptyString, "value": option3Value}
          ]
      
      ListView {
                  id: dataView
                  clip: true
                  spacing : 2
                  model: window.model
                  delegate: OptionDelegate{}
                  interactive: false
              }
      

      What I have tried is that I use a property in my model called visibilty for example. And I use this property in order to change the visible property of my delegate. It work I don't see my delegate anymore but it leave a blank in the list and I don't want that.

      Is there anyway to handle this ?

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

      hi,

      @DavidM29 said in Remove a ListElement from the ListView without removing it from the model:

      it work I don't see my delegate anymore but it leave a blank in the list and I don't want that.

      maybe you can try to set height to 0 when you set visible to false

      height : visible ? theHeight : 0
      
      D 2 Replies Last reply
      1
      • ODБOïO ODБOï

        hi,

        @DavidM29 said in Remove a ListElement from the ListView without removing it from the model:

        it work I don't see my delegate anymore but it leave a blank in the list and I don't want that.

        maybe you can try to set height to 0 when you set visible to false

        height : visible ? theHeight : 0
        
        D Offline
        D Offline
        DavidM29
        wrote on last edited by
        #3

        @LeLev
        Good idea I try it right away !

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

          hi,

          @DavidM29 said in Remove a ListElement from the ListView without removing it from the model:

          it work I don't see my delegate anymore but it leave a blank in the list and I don't want that.

          maybe you can try to set height to 0 when you set visible to false

          height : visible ? theHeight : 0
          
          D Offline
          D Offline
          DavidM29
          wrote on last edited by
          #4

          @LeLev
          It works it is a very simple and good idea ! Thank you !

          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