0

I am trying to create a simple GUI with QML, when the following occured:

  • Text items can be aligned using anchors under the ApplicationWindow

  • Copying the same code snipped (i just changed the id’s) inside a Tab results in an error: ReferenceError: textC is not defined. This results in textC being placed on top of textB (see also picture)

QML Code:

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
            }
        }
    }
}

Picture: http://s2.postimg.org/hzvyntxfd/info.png

As far as i know the anchors should work because textC and textD live under the same parent.

Am i missing something or is this just not allowed in QML?

Thanks in advance!

jrikken
  • 1
  • 2
  • `Tab` derives from `Loader`, so can probably only have one nested element. Try putting both the `Text` objects into a layout. – cmannett85 Sep 18 '14 at 10:35

1 Answers1

0

As cmannett85 pointed out, the Tab can only contain a single element. Encapsulating both text items with a layout (or a rectangle) does the trick!

jrikken
  • 1
  • 2