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. TreeView. How to get itemDelegate's property outside itemDelegate?
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 3.2k 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.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1
    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?

    kshegunovK 1 Reply Last reply
    0
    • K Kofr
      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?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kofr
        wrote on last edited by Kofr
        #3

        @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.

        kshegunovK 1 Reply Last reply
        0
        • K Kofr

          @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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @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.

          Read and abide by the Qt Code of Conduct

          K 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @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.

            K Offline
            K Offline
            Kofr
            wrote on last edited by Kofr
            #5

            @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?

            kshegunovK 1 Reply Last reply
            0
            • K Kofr

              @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?

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @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 ...

              Read and abide by the Qt Code of Conduct

              K 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @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 ...

                K Offline
                K Offline
                Kofr
                wrote on last edited by Kofr
                #7

                @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}
                kshegunovK 1 Reply Last reply
                0
                • K Kofr

                  @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}
                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @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.

                  Read and abide by the Qt Code of Conduct

                  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