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. Customization of component loaded with Loader.
Forum Updated to NodeBB v4.3 + New Features

Customization of component loaded with Loader.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 380 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.
  • B Offline
    B Offline
    BigZet
    wrote on last edited by
    #1

    Hello,
    Is there a way to modify property of component loaded by Loader?

    simple example:

    import QtQuick 2.7
    import QtQuick.Controls 2.3
    
        
    Rectangle {
        color: "#41cd52"
        anchors.fill: parent
        Component {
            id: comp
            Rectangle {
                width: 100
                height: 100
                color: "black"
            }
        }
        
        Loader {
            id: load
            sourceComponent: comp
            width: 200
            //item.color: "red" // non existing property! How to change it? 
        }
    }
    
    
    ODБOïO 1 Reply Last reply
    0
    • B BigZet

      Hello,
      Is there a way to modify property of component loaded by Loader?

      simple example:

      import QtQuick 2.7
      import QtQuick.Controls 2.3
      
          
      Rectangle {
          color: "#41cd52"
          anchors.fill: parent
          Component {
              id: comp
              Rectangle {
                  width: 100
                  height: 100
                  color: "black"
              }
          }
          
          Loader {
              id: load
              sourceComponent: comp
              width: 200
              //item.color: "red" // non existing property! How to change it? 
          }
      }
      
      
      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      @BigZet you can access the component using item property in js

      Loader {
       onStatusChanged: if(status === Loader.Ready){
                                       item.color = "red"
                                   }
      }
      
      1 Reply Last reply
      2
      • B Offline
        B Offline
        BigZet
        wrote on last edited by
        #3

        Thank you!
        Works great! :)

        1 Reply Last reply
        1
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          Or declaratively and to have actual bindings:

          Binding {
              target: loader.item
              property: "color"
              value: "red"
          }
          
          1 Reply Last reply
          2
          • ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #5
            item.color = Qt.binding(function() { return "red" })
            

            can work also

            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