代码之家  ›  专栏  ›  技术社区  ›  Aquarius_Girl

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

  •  0
  • Aquarius_Girl  · 技术社区  · 5 年前

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

    enter image description here

    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"
            }
        }
    }
    

    我有什么选择?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Aquarius_Girl    5 年前

    以下行必须添加到 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
                         }
    

    学分: https://stackoverflow.com/a/33972305/462608