简体   繁体   English

如何使用锚在 Flickable 中垂直间隔 QML 对象?

[英]How to space vertically QML objects in a Flickable using anchors?

How to space vertically QML objects in a Flickable using anchors?如何使用锚在 Flickable 中垂直间隔 QML 对象?

The code snippet (reproduced below in this message) is supposed to display texts and images supplied by a C++ model (the C++ object is named Global in this snippet). The code snippet (reproduced below in this message) is supposed to display texts and images supplied by a C++ model (the C++ object is named Global in this snippet).

I get an error message on the line:我收到一条错误消息:

anchors { top: _lblMsg1.bottom+8; }

You get the idea of what I'm trying to do: I want the top of the image to be 8 pixels lower than the bottom of the text above it.你明白我想要做什么:我希望图像的顶部比其上方文本的底部低 8 个像素。

I get an error message, though it seems to be working.我收到一条错误消息,尽管它似乎正在工作。

Could you tell me, please, how I can do this correctly?请你告诉我,我怎样才能正确地做到这一点?

<...>
Flickable {
    anchors.fill: parent;

    Label {
        id: _lblMsg1;
        text: Global.dataMessages.byId(Global.currService.msg_text1_id);
        anchors { top: parent.top; left:parent.left; right: parent.right; }
    }
    Image {
        id: _imgUri1;
        cache: false;
        source: (Global.currService && Global.currService.img_uri1 ? Global.currService.img_uri1 : "");
        asynchronous: true;
        anchors { top: _lblMsg1.bottom+8; left:parent.left; right: parent.right;}
        horizontalAlignment: Image.AlignHCenter;
        fillMode: (Image.width > 400 ? Image.Stretch : Image.Pad);
    }
<...>
}

Anchors only accept other anchor lines for their values.锚点只接受其他锚线作为它们的值。 However, you can use a margin to adjust the anchoring like so:但是,您可以使用边距来调整锚定,如下所示:

anchors { 
    top: _lblMsg1.bottom;
    topMargin: 8;
    left:parent.left;
    right: parent.right;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM