[Interest] Unexplained offset in QML
Alan Alpert
416365416c at gmail.com
Mon Jan 6 20:57:04 CET 2014
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
More information about the Interest
mailing list