[SOLVED] Problem with anchors within tabs



  • Hi all,

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

    • Text 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
    }
    
    TabView{
        anchors.top: textB.bottom
        Tab{
            title: qsTr("TEST")
            Text{
                id: textC
                text: qsTr("Test C")
            }
            Text{
                id: textD
                text: qsTr("Test D")
                anchors.left: textC.right
            }
        }
    }
    

    }@

    Picture:
    !http://s2.postimg.org/hzvyntxfd/info.png(info)!

    I was convinced this should work because textB and textC are living under the same parent.

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

    Thanks in advance!



  • Tab is inherited from Loader. It allows load one component. You will hit this issue in any platform. Just try include everything under one rectangle in tab

    @Tab {
    Rectangle {
    Text {}
    Text{}
    }
    }

    @

    This should work



  • Thanks! Works like a charm!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.