PDA

View Full Version : Getting item absolute position



nick85
11th December 2013, 15:42
Hi,

is there any easy way (or a trick) to get the absolute position of a widget?
I developed thinking that there was a property like this.

Thanks,

Nicola

Added after 21 minutes:

Ok .. I built it in a function


function getGlobalY(startingObject)
{
if(assert(startingObject, "[getGlobalY] Null starting object")) return;
if(isNull(startingObject.parent)) return startingObject.y;
if(!isNull(startingObject.isTop) && startingObject.isTop) return startingObject.y;

var result = startingObject.y;
var currentObject = startingObject.parent;
while(!isNull(currentObject))
{
if (!isNull(currentObject.isTop) && currentObject.isTop)
{
// finished
return result;
}

if (!isNull(currentObject.y))
{
// adding result
result += currentObject.y
}

currentObject = currentObject.parent;
}

printWarning("[getGlobalY] Not reached top!");
return result;
}

Note: isTop is a boolean property of my topScreen ..

wysota
16th December 2013, 15:06
What widget do you mean? A QtQuick item? There is a mapToItem() function in each item that allows to map coordinates between items.

nick85
19th December 2013, 09:12
yes a QtQuick item.
Ok, I can use mapToItem but function is still necessary?

wysota
19th December 2013, 17:58
What function?