[Qt-qml] Finding the coordinates of an item in a (Grid)View
alan.westbrook at nokia.com
alan.westbrook at nokia.com
Wed Nov 3 17:31:54 CET 2010
I was able to implement this for dragging, and it looks as if it should
work the same way for clicked, but there are a few levels of code it went
through for me it looks like.
1) Each of your GridItems needs to have a mouse area which fills your item
and invokes a parent signal clicked(index, x, y) a signal like this:
onClicked: { parent.clicked(index, mouse.x, mouse.y) }
2) The delegate for your grid view would look something like this:
Component {
id: itemsdelegate
Rectangle {
id: padding
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: 0
anchors.topMargin: 0
width: parent.height
color: "#00000000"
GridItem {
text: model.name
onClicked: { if (enabled) itemClicked(index, parent.x + x,
parent.y + y) }
}
}
}
I haven't tried the clicked case directly, but it did work well for the
dragging case.
You will need a 'proxy' element, that is, don't try to reparent the item
in the grid, just copy it's properties over to an item that does the
animation.
Alan
On 10/21/10 2:37 AM, "Kellomaki Pertti (Nokia-MS/Tampere)"
<pertti.kellomaki at nokia.com> wrote:
>I have a small problem, maybe someone on the list can help.
>
>I have an application with two views. In the first view, there are a
>number of items displayed in a GridView. In the second view there is
>just one item with some text beside it. What I am trying to accomplish
>is a smooth transition between two views. When an item is clicked in the
>first view, the selected item should slide to the left, and the rest of
>the items should fade away.
>
>The attached files contain a minimal implementation I have come up with.
>The only problem is that I cannot figure out how to start the animation
>of the selected item in the correct place, as indicated in the onClicked
>handler in the code. In other words, I need to find the coordinates of
>the selected item in the application's coordinate system. It seems that
>Item::mapToItem() should do the job, but I have not found a way to use
>it from QML without going via C++.
>
>It is certainly possible that there is a much better way to accomplish
>the same effect in QML. If so, please show me the error in my ways.
>--
>Pertti
>
More information about the Qt-qml
mailing list