javascript - 如何在 QML 的 TableView 中隐藏未使用的行?
问题描述
下面的代码显示了表中未使用的行。我希望未使用的行消失。应改为显示空白。
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 1.4
Window {
visible: true
width: 640
height: 480
TableView
{
height: 300; width: 300
TableViewColumn {
role: "title"
title: "Title"
width: 100
}
TableViewColumn {
role: "author"
title: "Author"
width: 200
}
model: libraryModel
}
ListModel {
id: libraryModel
ListElement {
title: "A Masterpiece"
author: "Gabriel"
}
ListElement {
title: "Brilliance"
author: "Jens"
}
ListElement {
title: "Outstanding"
author: "Frederik"
}
}
}
我有哪些选择?
解决方案
rowDelegate
必须在TableView中添加以下行:
readonly property int modelRow: styleData.row ? styleData.row : 0
rowDelegate: Rectangle
{
id: rowDel
border.width: 1
height: 52
width: 2000
readonly property int modelRow: styleData.row ? styleData.row : 0
}
推荐阅读
- reactjs - 无法启动赛普拉斯现实世界应用程序
- javascript - 反应图像未从数据库中渲染
- azure - Azure DevOps 中的声纳扫描仪错误 - 错误:未授权。请检查属性 sonar.login 和 sonar.password
- machine-learning - 从 lightgbm.basic.Booster 对象中读取超参数
- erl - erlang shell不能在同一台电脑上打乒乓球
- sql - 无法使用 Visual Basic 代码将对象从 DBNull 转换为其他类型
- python - 合并具有不同列的两个 spark 数据框以获取所有列
- javascript - 当我按下关闭时,移动版侧边菜单的转换有问题
- docker - 使用 REST API 自动设置 Keycloak
- javascript - 为什么 javasript 找不到变量?