【问题标题】:Loading tab from different file does not show anything. QML从不同文件加载选项卡不显示任何内容。 QML
【发布时间】:2016-03-27 22:25:05
【问题描述】:

我正在尝试将选项卡从不同的文件动态加载到 TabView 中。为此,我使用 Qt.createComponent 并将组件添加到视图中。该选项卡已加载,但其内容未显示并且已正确加载。像这样:

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

我做错了什么?

【问题讨论】:

    标签: qt qml qtquick2 tabview qtquickcontrols


    【解决方案1】:

    阅读@folibis 清理建议后,我意识到我获得Tab onCompleted 处理程序的方式不起作用。为什么我不知道。但是替换

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

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

    解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多