Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. dynamic Delegate component and use of DelegateModelGroup in DelegateModel

dynamic Delegate component and use of DelegateModelGroup in DelegateModel

Scheduled Pinned Locked Moved General and Desktop
delegatemodelgrdynamicdelegate
4 Posts 2 Posters 1.9k 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.
  • M Offline
    M Offline
    Mephi
    wrote on 10 Sept 2015, 14:17 last edited by Mephi 9 Oct 2015, 14:19
    #1

    Hello,
    i have a simple test qmlproject, where i create a dynamically a delegate for a gridview, this delegate is used in a DelagetModel with groups, but in the delegate the groups are undefined :-(
    here is a short example code:

    Rectangle {
        id: root
        anchors.fill: parent
    
        property var trackObjectViewDelegate: Qt.createComponent("DelegateItem.qml", root)
    
        DelegateModel {
            id: visualModel
    
            model: ListModel {
                ListElement { name: "blue" }
                ListElement { name: "green" }
                ListElement { name: "red" }
            }
    
            groups: [
                DelegateModelGroup { name: "selected" }
            ]
    
            delegate: trackObjectViewDelegate
        }
    
        GridView {
            id: gridID
            anchors.fill: parent
    
            model: visualModel
    
            cellHeight: 300
            cellWidth: 300
        }
    }
    

    in the DelegateItem.qml i try to read the selected property like this:

    Rectangle {
        id: item
        height: 25
        width: 200
        Text {
            text: {
                var text = "Name: " + name
                if (item.DelegateModel.inSelected)
                    text += " (" + item.DelegateModel.selectedIndex + ")"
                return text;
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: item.DelegateModel.inSelected = !item.DelegateModel.inSelected
        }
    }
    

    It is not working, and i get following error:
    TypeError: Cannot read property 'inSelected' of undefined

    Does anybody know what to do?
    If i not create the delegate dynamically, then it is working perfect, but this is not an option.

    P 1 Reply Last reply 11 Sept 2015, 08:14
    0
    • M Mephi
      10 Sept 2015, 14:17

      Hello,
      i have a simple test qmlproject, where i create a dynamically a delegate for a gridview, this delegate is used in a DelagetModel with groups, but in the delegate the groups are undefined :-(
      here is a short example code:

      Rectangle {
          id: root
          anchors.fill: parent
      
          property var trackObjectViewDelegate: Qt.createComponent("DelegateItem.qml", root)
      
          DelegateModel {
              id: visualModel
      
              model: ListModel {
                  ListElement { name: "blue" }
                  ListElement { name: "green" }
                  ListElement { name: "red" }
              }
      
              groups: [
                  DelegateModelGroup { name: "selected" }
              ]
      
              delegate: trackObjectViewDelegate
          }
      
          GridView {
              id: gridID
              anchors.fill: parent
      
              model: visualModel
      
              cellHeight: 300
              cellWidth: 300
          }
      }
      

      in the DelegateItem.qml i try to read the selected property like this:

      Rectangle {
          id: item
          height: 25
          width: 200
          Text {
              text: {
                  var text = "Name: " + name
                  if (item.DelegateModel.inSelected)
                      text += " (" + item.DelegateModel.selectedIndex + ")"
                  return text;
              }
          }
          MouseArea {
              anchors.fill: parent
              onClicked: item.DelegateModel.inSelected = !item.DelegateModel.inSelected
          }
      }
      

      It is not working, and i get following error:
      TypeError: Cannot read property 'inSelected' of undefined

      Does anybody know what to do?
      If i not create the delegate dynamically, then it is working perfect, but this is not an option.

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 11 Sept 2015, 08:14 last edited by
      #2

      Hi @Mephi and Welcome,

      TypeError: Cannot read property 'inSelected' of undefined

      The error says it exactly. The element is indefined and thus cannot access that property. Also I fail to see property named inSelected.

      You can either use parent or directly use id of DelegateModel.

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mephi
        wrote on 11 Sept 2015, 10:06 last edited by
        #3

        Hello p3c0,

        thanks for your reply, i know that the property inSelected is undefined, thats the intension of my question ;-) , but why it is undefined?

        it has to be defined, because it is working if i not create the delegate dynamically.

        inSelected property is generated automatically
        http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html#groups-prop

        P 1 Reply Last reply 12 Sept 2015, 13:52
        0
        • M Mephi
          11 Sept 2015, 10:06

          Hello p3c0,

          thanks for your reply, i know that the property inSelected is undefined, thats the intension of my question ;-) , but why it is undefined?

          it has to be defined, because it is working if i not create the delegate dynamically.

          inSelected property is generated automatically
          http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html#groups-prop

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 12 Sept 2015, 13:52 last edited by
          #4

          @Mephi Hmm, sorry for that. I wasn't aware of it as i have never used it before. So digging in it seems that the attached properties of DelegateModel doesn't seem to work if the delegate is in separate file. Could be a bug I suppose. You can try reporting it here.

          157

          1 Reply Last reply
          0

          3/4

          11 Sept 2015, 10:06

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved