I am having problems getting coordinate mapping to work as intended. For some reason the result is usually off, unless a very specific condition is met.
Here is an example scenario:
Objects are ordered in a tree, with each node being 100 pixels square. Mapping is done from each node to the parent of the first node. Items are paranted as they are ordered, e.g. 1 is parent of 2 and 4, 2 is parent of 3 and so on...
It seems like this mapping doesn't do what I assume it does, which is produce a coordinate, absolute to the object being mapped to, e.g. the top left corner of Node 0. Which should produce the expected values:
It seems that every new child at a given level skews the result off. Any idea what is going on here?
After investigating the mapToItem
method I concluded it is not the right tool for the job, so I wrote my own.
QPointF absolutePosition() {
QPointF p(0, 0);
QQuickItem * item = this;
while (item != Object::_rootUI) { // absolute position relative to _rootUI
p += item->position();
item = item->parentItem();
}
return p;
}