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. Access delegate item properties from outside
Forum Updated to NodeBB v4.3 + New Features

Access delegate item properties from outside

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 499 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
    maxwell31
    wrote on last edited by
    #1

    I have a flickable GridView. In this GridView I have custom buttons. My custom buttons change their border color when they are pressed, and when they are released, the border color changes back to the original.

    Now my problem: If I start a flick on a button, the border color is changing (which is OK). However, after the flick is done, the release event is stolen by the GridView, so the button color does not change back. I thought I will fix this by creating a function which is called inside onFlickEnded{}:

    function resetButtonColorAfterFlick() {
        var i
        for(i=0; i<gridView.model.count;i++) {
            var myob =gridView.children[0].children[i]
            if(myob.children[0].state=="normal")
                myob.children[0].border.color="#646464"
        }
    }
    

    While this is working, I don't know how I am supposed to access the delegate properties here. The above solution with children cannot be how it is supposed to be done, or?

    Gojir4G 1 Reply Last reply
    0
    • M maxwell31

      I have a flickable GridView. In this GridView I have custom buttons. My custom buttons change their border color when they are pressed, and when they are released, the border color changes back to the original.

      Now my problem: If I start a flick on a button, the border color is changing (which is OK). However, after the flick is done, the release event is stolen by the GridView, so the button color does not change back. I thought I will fix this by creating a function which is called inside onFlickEnded{}:

      function resetButtonColorAfterFlick() {
          var i
          for(i=0; i<gridView.model.count;i++) {
              var myob =gridView.children[0].children[i]
              if(myob.children[0].state=="normal")
                  myob.children[0].border.color="#646464"
          }
      }
      

      While this is working, I don't know how I am supposed to access the delegate properties here. The above solution with children cannot be how it is supposed to be done, or?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @maxwell31 Hi,

      How do you make the border color changing ? Can we see the code of the delegate ?
      In my opinion it's better to handle this in the code of the button instead of accessing to the delegate to change it's state.

      Here is a simple code which work on my side. It uses the State mechanism:

      //main.qml
      import QtQuick 2.9
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
      
          GridView{
              anchors.fill: parent
              model: 50
              delegate: MyButton{
                  text: "" + index
              }
          }
      }
      
      //MyButton.qml
      
      Button {
          background: Rectangle{
              id: bg
              border.width: 1
              border.color: "blue"
          }
      
          states: [
              State {
                  name: "pressed"
                  PropertyChanges { target: bg; border.color: "red" }        }
          ]
          state: pressed ? "pressed" : ""
      }
      
      1 Reply Last reply
      1

      • Login

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