首页 > 解决方案 > 在“AppListView”中是加载器应该使用“SimpleRow”加载组件的空白位置

问题描述

我在 github 上有一个用 QT/QML 和 V-PLAY 编写的代码应用程序

我的问题:

我想使用 AppListView 在“Ustawienia”(设置)页面中显示不同的元素(如 Button 或 SwitchApp),具体取决于数组中的元素:

property var typeOfElementsInSettings: ['switch','switch','button','switch']

我使用 'delete: Loader' 来做这件事,我在这个线程中得到了启发。我从其他文件加载组件,一个里面有 Button,另一个 AppSwitcher。Loader 将 SimpleRow 插入 AppListView,我知道它是因为当添加 SimpleRow 时变量 myIndex 应该增加并且它增加了,但我什么都看不到。我的意思是我看到应该显示 SimpleRow 的地方有空白。

看截图:

安卓主题:

安卓主题

iOS 主题:

ios主题

这是我在 Main.qml 中的代码

NavigationItem{
            title: "Ustawienia"
            icon: IconType.cogs

            NavigationStack{
                Page{
                    title: "Ustawienia"
                    AppButton{
                        id: przy
                        text: "abba"
                    }

                    AppListView{
                        anchors.top: przy.bottom
                        model: ListModel{
                            ListElement{
                                type: "kategoria 1"; name: "opcja 1"
                            }
                            ListElement{
                                type: "kategoria 1"; name: "opcja 2"
                            }
                            ListElement{
                                type: "kategoria 2"; name: "opcja 3"
                            }
                            ListElement{
                                type: "Opcje programisty"; name: "Czyszczenie ustawień aplikacji"
                            }
                        }


                        section.property: "type";
                        section.delegate: SimpleSection {
                            title: section
                        }

                        delegate: Loader{
                            sourceComponent: {
                                switch(typeOfElementsInSettings[myIndex]){
                                    case "switch":
                                        console.log(typeOfElementsInSettings[myIndex])
                                        console.log("s")
                                        return imageDel;
                                    case "button":
                                        console.log(typeOfElementsInSettings[myIndex])
                                        console.log("b")
                                        return imageDel;
                                }
                            }
                        }
                        SimpleRowSwitch { id: imageDel }
                        VideoDelegate { id: videoDel }
                    }

                }
            }
            onSelected: {
                //console.log("selected")
            }
            Component.onCompleted: {
                //console.log("Zrobiono")
            }
        }

这是我在 SimpleRowSwitch.qml 中的代码:

import VPlayApps 1.0
import QtQuick 2.9

Component{
    SimpleRow {
        x: 100
        y: 200
        text: name;
        AppSwitch{
            property int indexOfElementInSettings: 0
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: dp(10)
            Component.onCompleted: {
                indexOfElementInSettings=myIndex
                console.log(myIndex)
                if(switchsSettingsLogicArray[myIndex]===1){
                    checked=true
                } else {
                    checked=false
                }
                //myIndex++;
            }
            onToggled: {
                console.log(indexOfElementInSettings)
            }
        }
        Component.onCompleted: {
            console.log(x)
            console.log(y)
            console.log(typeOfElementsInSettings[myIndex])
            console.log(myIndex)
            myIndex++
        }
        onSelected: {
            console.log("abba")
        }
    }
}

标签: qtqmlv-play

解决方案


推荐阅读