Important: Please read the Qt Code of Conduct -

[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")

        id: textA
        text: qsTr("Test A")
        id: textB
        text: qsTr("Test B")
        anchors.left: textA.right
    TabView{ textB.bottom
            title: qsTr("TEST")
                id: textC
                text: qsTr("Test C")
                id: textD
                text: qsTr("Test D")
                anchors.left: textC.right



    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!

  • Qt Champions 2017

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


    This should work

  • Thanks! Works like a charm!

Log in to reply