TreeView. How to get itemDelegate's property outside itemDelegate?



  • Controls1.TreeView {
                    id: tv1
                    anchors.fill: parent
                    model: treeModel
                    headerVisible: false
                    itemDelegate: PlanItemDelegate {
                        id: planItemDelegate
                        fullMdl: tv1.model
                        indx: styleData.index                   
                        closedHeight: mainW.height / 12
                        open: styleData.selected
                        onButtonMinimizeClicked: {
                            root.changeCurrentIndex(-1)
                        }
                    }
                    rowDelegate: Rectangle {
                        height: ///////// ???? how to make it equal to itemDelegate.height?
                        color: "white"                  
                    }
                    style: TreeViewStyle {
                        branchDelegate: Rectangle {
                            color: "transparent"
                            height: 80
                            width: height
                        }                    
                    }
    }
    

    How to get itemDelegate's height outside itemDelegate?


  • Qt Champions 2016

    @Kofr said:
    I'm a complete QML noobster, but doesn't this:

    rowDelegate: Rectangle {
        height: planItemDelegate.height
        color: "white"                  
    }
    

    just work?

    PS.
    ... assuming the PlanItemDelegate component has that property.



  • @kshegunov, Yes, it has property height

    rowDelegate: Rectangle {
                        height: planItemDelegate.height
    ...
    

    ReferenceError: planItemDelegate is not defined
    And this is real trouble to get this property. I have not found approach to get it.


  • Qt Champions 2016

    @Kofr
    Hm, I'm just guessing, but I'd also try reshuffling like this:

    itemDelegate: planItemDelegate
    
    PlanItemDelegate {
        id: planItemDelegate
        fullMdl: tv1.model
        indx: styleData.index                   
        closedHeight: mainW.height / 12
        open: styleData.selected
        onButtonMinimizeClicked: {
            root.changeCurrentIndex(-1)
        }
    }
    
    rowDelegate: Rectangle {
        height: planItemDelegate.height
        color: "white"                  
    }
    

    This is how I anchor things to one another, at least in a very similar matter.



  • @kshegunov it does not work out in this case as this delegate uses styleData.index and styleData.selected which is different for every delegate.
    And if I reference this object by id, how do I bind delegate specific properties?


  • Qt Champions 2016

    @Kofr
    What is styleData?

    And if I reference this object by id, how do I bind delegate specific properties?

    I'm not sure I understand the question. What delegate specific properties you want to bind, and to what?
    Do you mean something like this:

    Text  {
        text: planItemDelegate.closedHeight
    }
    

    Do bear in mind, that as I noted my whole experience with QML totals the 2 hours I put in this evening, so I may be completely misleading you ...



  • @kshegunov said:

    indx: styleData.index
    closedHeight: mainW.height / 12
    open: styleData.selected

    ...
    indx: styleData.index                   
        ...
        open: styleData.selected
    ...
    

    the internal properties of PlanItemDelegate depends on styleData.* properties, so if I try to make

    itemDelegate: planItemDelegate
    

    I can not bind this custom properties. Or Now I think about some js function like

    itemDelegate: {var copyObj = planItemDelegate; copyObj.index = Qt.binding(function() {return styleData.index }); copyObj}

  • Qt Champions 2016

    @Kofr said:

    the internal properties of PlanItemDelegate depends on styleData.* properties, so if I try to make

    But they're already bound.

    PlanItemDelegate {
        id: planItemDelegate
        fullMdl: tv1.model
        indx: styleData.index                     //< This is a binding, isn't it?
        closedHeight: mainW.height / 12
        open: styleData.selected
        onButtonMinimizeClicked: {
            root.changeCurrentIndex(-1)
        }
    }
    

    What difference does it make if you create the PlanItemDelegate and then pass the reference by id, or just pass the reference. I don't see any difference or problem whatsoever. Perhaps I'm wrong, but it really seems the same to me. The only thing I don't know is where the styleData object is defined ...

    PS.
    I have now encountered styleData, but am still not sure where it comes from, or rather how it's supposed to be accessed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.