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. Change delegate properties afterwards.
Forum Updated to NodeBB v4.3 + New Features

Change delegate properties afterwards.

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

    Hello,

    is there a way to change the properties of a delegate after a List is completed.

    lets say I have a model like this
    @ ListModel {
    id: menu_model
    ListElement {
    index: 1
    label: "foo"
    }
    ListElement {
    index: 2
    label: "bar"
    }
    }@

    And a ListView like this
    @ ListView {
    id:menu_list
    anchors.fill: parent
    model: menu_model
    delegate: Item {
    width: parent.width
    height: 50 //this propertie must be changed dynamically
    Rectangle {
    anchors.fill: parent
    border.color: "grey"
    Text {
    text: label
    }
    }
    }@

    I need is to change the height of a specific Delegate according to other programm logik.
    How can I access a specific list Item to change its properties ?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Hey Schneidi,

      yes it is possible. You can get an Item using:
      @menu_model.get(i)@
      To get the current index or an index at a Position you can use:
      @menu_list.currentIndex()
      menu_list.indexAt(x, y)@
      You could also get an Item at a Position:
      @menu_list.itemAt(x, y)@
      To change it's properties just access it's property like you normaly would do:
      @menu_model.get(i).label = "foobar"@

      Another method would be to iterate trough all children of your ListView and check for .index.
      @for(var i = 0; i < menu_list.children.lenght(); i++)@
      If the child has got a index it could access it, otherwise it would print "no property found" or something like that. Nothing important, it just couldn't access the property because it hasn't the property index. They you can check for a specific index like:
      @if(menu_list.children[i].index == 2){
      // Child with Index 2
      }@

      Feel free to ask if you've got questions.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schneidi
        wrote on last edited by
        #3

        Hey onek24,

        ok with this approach I access the properties of the model right ?
        Is there also a way to change the height property of the delegate Item {}
        like the one above ?
        @height: 50 //this propertie must be changed dynamically@

        Or do I have to pass the height via the model and change the height in the model ?

        1 Reply Last reply
        0
        • O Offline
          O Offline
          onek24
          wrote on last edited by
          #4

          [quote author="Schneidi" date="1392378277"]Hey onek24,

          ok with this approach I access the properties of the model right ?[/quote]
          Yes, you access the model OR you could access the item/children by itself. I provided the code for that above, too. But keep in mind: QML delegates are construkted and destroyed dynamically. Only visible delegates are existent.

          [quote author="Schneidi" date="1392378277"]
          Is there also a way to change the height property of the delegate Item {}
          like the one above ?
          @height: 50 //this propertie must be changed dynamically@

          Or do I have to pass the height via the model and change the height in the model ?[/quote]
          You can change the height of it using:
          @menu_model.get(i).height = 50@

          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