How to get a Children of a Component
-
I have a ListView, wich loads for the delegate a separate QML component.
@
Component {
id: comItem {
id: itImage { id: img ... } Text { id: txt ... }
}
}
@Now I want to define some Transitions for one Element (scale of img for example) of the component, but i can not get the Item id or com.children.
Or is there anonther possibility in QML to define Transitions by switching the center element in a Listview?
I'm using Qt 5 Alpha and QtQuick 2. Only QML, no C++.
Can anyone help me?
Thank You.
-
To access the items in the delegate you will need to expose them in the delegate's root object, e.g. using an alias:
@
Component {
id: comItem { id: it property alias image: img property alias text: txt Image { id: img ... } Text { id: txt ... } } }
@
-
Hi, thank You for Your answer.
I know the method with property alias, but then I have to create a property alias in Component.
But then i get the error - Component objects cannot declare new properties -.When i get access to Item, then i can use it.children, too.
-
Can't you do the transition in the Item itself, based on a property set in the model or the current item or something like that?
-
I tried this, too. I can define States and Transitions, but then my problem is that I can not call this state of the item because i get no access to the children oh the Component.
-
Hi,
I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
The delegate of the ListView contains a Img and I want to scale it while changing.Is this possible?
Thank You.
-
I'm sorry, I must have been unclear.
Why don't you add the appropriate roles to the model itself, and use that to trigger the transitions?
Perhaps you should try to explain a bit more about why you think you need to have this access (which you will not get). What effect do you want to achieve?
Edit:
[quote author="Gihu" date="1340970210"]Hi,
I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
The delegate of the ListView contains a Img and I want to scale it while changing.Is this possible?
[/quote]
Just use the isCurrentItem attached property of the delegate to determine the size of the image, and use a behavior to make an animation of that change. -
[quote author="Gihu" date="1340970210"]Hi,
I'm using Qt 5 Alpha, QtQuick 2 and want to define Transitions when I switch the CurrentIndex (not the highlight) of a ListView.
The delegate of the ListView contains a Img and I want to scale it while changing.Is this possible?
Thank You. [/quote]
moderators note: I have merged in the above posting, that was posted as a separate topic. It really looks to me as if this is on the same problem. Please don't open multiple topics on the same problem.
-
That is right. Sorry.
I'm now trying, to use State/Transition in the ListView model, that works.
But first I tried only to change the property of one Element of the ListViews Component, so i needed access to the components children.
Is this the only possibility to add Transitions between switching the ListViews CurrentIndex?
-
If you want to trigger something like this from outside of the listview & delegates themselves, you'll have to resort to modifying the model itself. You can add a role in the model that you can use to trigger a change like you want. Then, from the outside, you can modify the item you want.
However, for the case you are describing, the original solution sounds much simpler.
All in all, you have to realize that from outside the list view, you have no direct access to your delegates, but your delegates can access other QML items.
-
Thank You for your answers.
I'm sorry, but I already don't exactly understand how to doit.
@ ListView {
id: listview_centermodel: listmodel_center //<-- Is my separate .qml ListView {...} delegate: component_center //<-- Is my seperate .qml Component {...}, see the posts before anchors.fill: parent orientation: ListView.Horizontal focus: true
}@
I set the next Item from the list with this call:
@listview_center.positionViewAtIndex(value_menu_center_current,ListView.Center)@
I use it so, because I only want to display always one element (without the swaping from the end to the beginning).
Can You please explain again how to manage Transtitions/Animations between switch to next Item of the List.
Thank You very much.
-
This post is deleted!