0
我想從另一個文件中動態加載標籤到TabView中。爲此,我使用Qt.createComponent並將該組件添加到視圖中。該選項卡已加載,但其內容不顯示,並且已正確加載。就像這樣:從不同文件加載標籤不顯示任何內容。 QML
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();
}
與 「tab.qml」 文件:
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
}
}
}
我該怎麼辦錯了嗎?