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. Attached properties to access parent Loader from loaded Item?
Qt 6.11 is out! See what's new in the release blog

Attached properties to access parent Loader from loaded Item?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 843 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by
    #1

    Are any properties attached to the item loaded by a Loader that would facilitate access of the parent Loader properties from the loaded Item?

    As an example, I would like to dismiss a loaded item on a button press. The item is loaded within the scope of the Loader so Loader properties can be accessed directly. Thus I can set sourceComponent = undefined within the loaded Item and that works. But what if I wanted to set the Loader opacity to 0 for instance? I cannot directly set the opacity (unlike sourceComponent) because that applies to the opacity of the specific QML element within the loaded Item. I can do loaderName.opacity = 0 and that works, but that ties the Item to a specific Loader.

    Just like a ListView is accessible within its delegate, is there anything analogous for Loader? If not, is there any idiomatic way to access parent Loader properties from a loaded Item?

    1 Reply Last reply
    0
    • vikramgV Offline
      vikramgV Offline
      vikramg
      wrote on last edited by
      #2

      It looks like the easiest way to accomplish this is to inject a property into the loaded Item by simply defining it on the Loader itself:

         Loader {
             id: myLoader
             anchors.centerIn: parent
             property alias loaderOpacity: myLoader.opacity
             ...
         }
      

      Now loaderOpacity can be used to change parent Loader opacity from the loaded Item.

      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