Global position of a QQuickItem.
-
So this has been asked before, but I haven't found anything to address it since QQuickItem replaced QDeclarativeItem. Here is the original question. WRONG LINK -http://qt-project.org/forums/viewthread/48092/- CORRECT LINK http://qt-project.org/forums/viewthread/10013
The basic question is how do I know when a QQuickItem moves on the screen? How do I know if the x,y of it or any ancestor has changed? I am trying to implement a sort of tooltip that has to follow the item wherever it goes and because of transform elements (which don't edit x or y) I can't really tell where the item is on the screen and if that has changed.
EDIT: I am dumb and copied the wrong link. I have corrected that. I will also add that I cannot find a QQuickItem::itemChange that says that the scene position changed like QGraphicsItem::itemChange did. That is why I am asking this question.
-
Hi,
bq. How do I know if the x,y of it or any ancestor has changed?
Did you try onXChanged,onYChanged and onParentChanged signal handlers ?
bq. I am trying to implement a sort of tooltip that has to follow the item wherever it goes and because of transform elements (which don’t edit x or y) I can’t really tell where the item is on the screen and if that has changed.
Can you provide a small example for better understanding ?
P.S: The link you posted is different I guess.
-
Hi buttink,
look at "this post":http://qt-project.org/forums/viewthread/53542/ . Hope it helps somehow.
-
@p3c0 I'm an idiot and somehow copied the wrong link. /facepalm Let me edit my question really quick.
@Weiland I have a solution kind of like that in QML, but you tell it what to use for the mapFromItem. The problem is that now if the item gets translated, like from a listview, the position changes but the X, Y, and Parent are all the same.
-
Tricky :-/
-
Just for reference this what I am currently using
@Item {
id: root
x: d.rect.x
y: d.rect.y
height: d.rect.height
width: d.rect.width/** * The target to be a ghost anchor for. */ property Item target: root /* * TODO: Deal with the fact that floating anchor may anchored to a target that's inside a flickable (and therefore * its x and y won't change when scrolling) * * See thread: http://qt-project.org/forums/viewthread/10013 * */ Item { id: d property var rect: root.parent ? root.parent.mapFromItem(target.parent, target.x, target.y, target.width, target.height) : Qt.rect(0,0,0,0) }
}@
-
After doing some research, it makes sense that the scene position isn't on the QQuickItem because the scene graph should be rendering everything. The thing I'm not positive about is if QML just messes with transformers and no one is notified of updated transformers. It would make some sense considering how OpenGL works, so I'm not really sure how I am supposed to be able to pull this off.
-
For anyone in the future, I think this could be possible by making a QSGTransform node that would move the entire subtree up making it show on the screen. I don't know how QtQuick uses the z-value though so I am looking into it.
-
We came to the same conclusion, i.e. you need to create some QSGNode and capture the global position with it.
To your Z question, what we do is to create in your main qml file an item with a very large Z value after all the others and put the item we wan't to position globally into that. That way its always on top and what remains is to set its location based on the capture from the node ( or you could try to directly access its QSGTransform node and change the X/Y of ).
Cheers,
Moeren