[Interest] Unexplained offset in QML

Jason H scorp1us at yahoo.com
Thu Jan 9 16:28:34 CET 2014


Thanks Alan. Actually, A this the case. However I don't understand why it matters?

The "missing code" is just the Animal.qml, that only nests the elements accordingly for layering/grouping:
Item {
 Item { id: head 
   Item { id: earL}
   Item { id: earR}

   Item { id: face}

}
}
Item { id: tail}
}


The only time the offsets, sizes, and sources are set are in the code I posted in the first message. 
I would assume that all locations are 0,0 by default, so there should be no offset of the head.
(also the offset applies to the body and everything else)






________________________________
 From: Alan Alpert <416365416c at gmail.com>
To: Jason H <scorp1us at yahoo.com> 
Cc: "interest at qt-project.org" <interest at qt-project.org> 
Sent: Monday, January 6, 2014 2:57 PM
Subject: Re: [Interest] Unexplained offset in QML
 

On Fri, Jan 3, 2014 at 2:08 PM, Jason H <scorp1us at yahoo.com> wrote:

> I have a QML object that is several Images. When I load the whole thing, I
> do it as a two-step process. The first is a static QML file that properly
> nests the objects. That is inherited by one that sets the source and
> location of the images.
>
> The images are correct, with no white space. The offsets are correct. But
> when displayed, it is horizontally offset. The width is properly calculated.
>
> Some code is below:
>
>
> Animal {
> function objName() { return 'puppy1';}
> id: puppy1
> Rectangle { anchors.fill: parent; opacity: 0.2; color: "purple";
> border.width: 1}
> Rectangle { x:0; y:0; width: 10; height:10; opacity: 0.5; color: "red";
> border.width: 1}
> Component.onCompleted: {
> tail.source = objName() + '/tail.png';
> tail.x=35.94994652;
> tail.y=228.608;
>
> earL.source = objName() + '/ear-l.png';
> earL.x=218.11224652;
> earL.y=9.721;
>
> earR.source = objName() + '/ear-r.png';
> earR.x=0.0;
> earR.y=9.721;
>
> Now, what happens here is the purple rectangle is the proper size and
> location. Same for the red rectangle, but all the image objects are too far
> to the right (tail, earL and earR). Even though the purple rect's anchors
> are fill parent (the puppy1) the images extend past the purple box. This
> should not be possible. EarR.x is set to 0.0, so it should be on the left
> edge, but it isn't.
>
> I have no idea hoe to explain or fix this. Ideas?

You haven't provided enough source code to identify the problem, but
two possibilities spring to mind:

A) The images aren't direct children of the Animal root Item, and thus
have an offset applied via their parent's x coordinate.
B) The images are on a fill mode which respects aspect or original
size, and the images are thus being centered in a manual size you've
given to the Image elements.

--
Alan Alpert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140109/3b29bd2e/attachment.html>


More information about the Interest mailing list