2015-12-21 62 views
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 
     } 
    } 
} 

我該怎麼辦錯了嗎?

回答

0

閱讀@folibis清理建議後,我意識到我得到TabonCompleted處理程序無法正常工作的方式。爲什麼我不知道。然而,隨着

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

更換

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

解決它。