qt - Enable 属性不适用于 tableview 和 delegateChooser QML
问题描述
import QtQuick 2.15
import QtQuick.Controls 2.15
import Qt.labs.qmlmodels 1.0
ApplicationWindow {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
TableView {
anchors.fill: parent
columnSpacing: 1
rowSpacing: 1
clip: true
model: TableModel {
id:tableModelId
TableModelColumn { display: "name" }
TableModelColumn { display: "surname" }
TableModelColumn { display: "age" }
TableModelColumn { display: "adresse" }
TableModelColumn { display: "profil" }
TableModelColumn { display: "status" }
rows: [
{
"name": "max",
"surname": "myller",
"age": 16,
"adresse": "California",
"profil": "students",
"status": false
},
{
"name": "max",
"surname": "myller",
"age": 16,
"adresse": "California",
"profil": "students",
"status": false
},
{
"name": "max",
"surname": "myller",
"age": 16,
"adresse": "California",
"profil": "students",
"status": false
}
]
}
delegate: DelegateChooser {
id: delegateID
DelegateChoice {
column: 0
delegate: Rectangle {
implicitWidth: 100
implicitHeight: 50
color: "dodgerblue"
TextField {
id:nameId
text: model.display
font.pixelSize: 10
anchors.centerIn: parent
// enabled:
// Component.onCompleted: strategyChoice = strategyTextId.currentText
// onActivated:strategyChoice = strategyTextId.currentText
}
}
}
DelegateChoice {
column: 1
delegate: Rectangle {
implicitWidth: 100
implicitHeight:50
TextField {
text:model.display
font.pixelSize: 10
anchors.centerIn: parent
// It doesn't work
enabled:(model.status) ? true : false
}
}
}
DelegateChoice {
column: 2
delegate: Rectangle {
implicitWidth: 100
implicitHeight:50
ComboBox {
anchors.centerIn: parent
model: ["1","2","3","4","5","6","16"]
}
}
}
DelegateChoice {
column: 3
delegate: Rectangle {
id: rectangle
implicitWidth: 100
implicitHeight:50
TextField {
font.pixelSize: 10
text: model.display
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
placeholderText: qsTr("Enter balance")
}
}
}
DelegateChoice {
column: 4
delegate: Rectangle {
implicitWidth: 100
implicitHeight:50
ComboBox {
id:profilId
model:["Students","engineers","lawyer","doctor"]
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
// it doesn't work
enabled: (controlactivate.text === "OFF") ? true : false;
}
}
}
DelegateChoice {
column: 5
delegate:Rectangle {
implicitWidth: 80
implicitHeight:30
TabButton{
id:controlactivate
property string colorToUse : "#b41414"
anchors.centerIn: parent
text: model.display ?"ON" :"OFF"
contentItem: Text {
text: controlactivate.text
opacity: enabled ? 1.0 : 0.3
color: (controlactivate.text === "OFF") ? "#b41414" :"#17a81a"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
opacity: enabled ? 1 : 0.3
border.color: (controlactivate.text === "OFF") ? "#b41414" :"#17a81a"
border.width: 1
radius: 2
}
onClicked: {
console.log("Follow: " + model.index)
if(controlactivate.text === "OFF"){
controlactivate.text = "ON"
}else{
controlactivate.text = "OFF"
}
}
}
}
}
}
}
}
我有一个带有模型和委托的表格视图。当我单击特定行中的 tabButton 时,我试图将所有启用属性设置为 true 或 false,但我尝试过的所有操作都不起作用。我正在尝试使其动态化,这意味着每次单击打开或关闭按钮时,它都会启用或禁用该组件。我已经尝试过属性绑定,但听起来属性绑定不能与委托正常工作。
图像以获得预期的大图
解决方案
推荐阅读
- django-models - 有没有办法根据相关模型的布尔值过滤模型表单?
- javascript - 从 moment.js 到 date-fns:UTC 格式问题
- ruby-on-rails - Rails 仅在生产环境中设置 session_store
- c++ - 定义一个宏,该宏仅在指数为整数的情况下定义 pow 函数
- node.js - 在 Gitlab 管道中安装依赖项时出错
- python - pyspark 和 anaconda 环境出错
- javascript - 在 Nuxt 应用程序中访问 div 的高度会引发错误消息
- python - 使用 pandas 将 .csv 文件转换为科学计数法
- javascript - Ant Design upload component - enable sending multiple files in single request
- google-sheets - 如何在 Google Apps 脚本(Google 表格)中安全地使用凭据