qt - 在“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 主题:
这是我在 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")
}
}
}
解决方案
推荐阅读
- angular - Angular 使用中的 Merge Map 运算符
- azure - ProcessEventsAsync 中的延迟检查点
- mongodb - 复制处于活动状态时无法删除“本地”数据库
- javascript - 使用 Selenium 和 Node.js 进行自动化测试
- azure - 如何删除数据工厂中的链接服务?
- javascript - 如何循环播放一组音频文件一定次数?不是无限的
- firebase - Crashlytics,仪表板中受影响的用户数量没有意义
- excel - 如何在excel中的特定单元格上对特殊字符进行文本验证?
- swift - 如何从txt文件中读取变量?
- ruby-on-rails - 如何使用 Ruby on Rails 制作易于交互的图像分类系统