0

I am trying to load tabs dynamicly into a TabView from a different file. For this I am using Qt.createComponent and adds the component to the view. The tab is loaded but it's content does not show up and it is properly loaded. Like this:

TabView {
   id:editor
   Layout.minimumWidth: 50
   Layout.fillWidth: true
}

Component.onCompleted: {
    function newTab() {
        var c = Qt.createComponent("tab.qml");
        editor.addTab("tab", c);
        var last = editor.count - 1;
        editor.getTab(last).active = true;
    }

    newTab();
    newTab();
}

And the "tab.qml" file:

import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.4


Tab {
    Rectangle {
        Layout.fillWidth: true
        Layout.fillHeight: true
        color: "lightgray"

        TextArea {
            anchors.fill: parent
        }
    }
}

What do I do wrong?

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Jerry
  • 13
  • 5

1 Answers1

0

After reading @folibis clean-up suggestion I realized the way I got the Tab onCompleted handler wasn't working. Why I don't know. However replacing

var c = Qt.createComponent("tab.qml");
editor.addTab("tab", c);
var last = editor.count - 1;
editor.getTab(last).active = true;

with

var c = Qt.createComponent("tab.qml");
var tab = editor.addTab("tab", c);
tab.active = true

solved it.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Jerry
  • 13
  • 5