如何隐藏 QML 中 TableView 中未使用的行?

下面的代码显示了表中未使用的行。我希望未使用的行消失。应显示空白。

https://img4.mukewang.com/650c052c0001f6fd03690366.jpg

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"

        }

    }

}

我有什么选择?


蓝山帝景
浏览 93回答 1
1回答

蝴蝶刀刀

必须在rowDelegateTableView 中添加以下行: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                      }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript