Scope trouble. Accessing propeties out of scope.
-
Let's say I have the following situation:
Rectangle { id: recOne property bool isRed: false color: isRed ? "red" : "blue" } Item { id: someItem Rectangle { id: recTwo property bool isRed: recOne.isRed color: isRed ? "red" : "blue" } }
Now let's say I want to wrap the first Rectangle in a
Component
like so:Component { id: component_recOne Rectangle { id: recOne property bool isRed: false color: isRed ? "red" : "blue" } }
I realize that I can create some alias for the loader of this component and access it's
item
in order to see theLoader
's item properties but what if I need to access recOne properties when it is not currently the active source component of the loader? For instance, what if the loader will have many other components outside of just recOne but recTwo will always need to know what color to be reguardless of what theLoader
's current active component is? Wrapping recOne in aComponent
like that takes it's properties out of scope for recTwo. How do I bring them back into scope? -
Let's say I have the following situation:
Rectangle { id: recOne property bool isRed: false color: isRed ? "red" : "blue" } Item { id: someItem Rectangle { id: recTwo property bool isRed: recOne.isRed color: isRed ? "red" : "blue" } }
Now let's say I want to wrap the first Rectangle in a
Component
like so:Component { id: component_recOne Rectangle { id: recOne property bool isRed: false color: isRed ? "red" : "blue" } }
I realize that I can create some alias for the loader of this component and access it's
item
in order to see theLoader
's item properties but what if I need to access recOne properties when it is not currently the active source component of the loader? For instance, what if the loader will have many other components outside of just recOne but recTwo will always need to know what color to be reguardless of what theLoader
's current active component is? Wrapping recOne in aComponent
like that takes it's properties out of scope for recTwo. How do I bring them back into scope?@RobM said in Scope trouble. Accessing propeties out of scope.:
How do I bring them back into scope?
-
@RobM said in Scope trouble. Accessing propeties out of scope.:
How do I bring them back into scope?
@fcarney That's what I was trying to say in my first post. Calling the <loaderid>.item.<property> works if the loader always has that component loaded but not otherwise. I was hoping there was a simple way to gain access to a components properties without accessing the loader.
-
@fcarney That's what I was trying to say in my first post. Calling the <loaderid>.item.<property> works if the loader always has that component loaded but not otherwise. I was hoping there was a simple way to gain access to a components properties without accessing the loader.
-
Are you wanting the Rectangle to exist when not visible or the data? If its the latter then take a data driven approach rather than messing with Items. You can build a ListModel in QML with your data and access the data inside that. Then it is primed to be used with various views.