QML:标签内的锚点

时间:2014-09-17 19:11:36

标签: qt qml qt-quick

我正在尝试使用QML创建一个简单的GUI,当发生以下情况时:

  • 可以使用ApplicationWindow

  • 下的锚点对齐文本项目
  • 在Tab中复制相同的代码剪切(我刚刚更改了id)会导致错误:ReferenceError:textC未定义。这导致textC被放置在textB的顶部(参见图片)

QML代码:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 640
    height: 480
    title: qsTr("MyApp")

    Text{
        id: textA
        text: qsTr("Test A")
    }
    Text{
        id: textB
        text: qsTr("Test B")
        anchors.left: textA.right //aligns textB nicely against textA
    }

    TabView{
        anchors.top: textB.bottom //also alignts TabView nicely against textB
        Tab{
            title: qsTr("TEST")
            Text{
                id: textC
                text: qsTr("Test C")
            }
            Text{
                id: textD
                text: qsTr("Test D")
                anchors.left: textC.right //nope... this doesn't work even though
                                          //textC lives under the same parent
            }
        }
    }
}

图片:http://s2.postimg.org/hzvyntxfd/info.png

据我所知,锚点应该起作用,因为textC和textD位于同一个父级下面。

我错过了什么或者这是不允许的QML?

提前致谢!

1 个答案:

答案 0 :(得分:0)

正如cmannett85所指出的,Tab只能包含一个元素。用文本项(或矩形)封装两个文本项就行了!