QML TableView with dynamic number of columns

前端 未结 2 1139
[愿得一人]
[愿得一人] 2020-12-25 08:58

I have been trying to use a QML TableView to display a QAbstractTableModel. The missing part of the equation seems to be that it is not possible to

2条回答
  •  粉色の甜心
    2020-12-25 09:20

    The solution with resources does not work for me (Qt 5.6). The TableView is not updated.

    This works for me:

    Component{
        id: columnComponent
        TableViewColumn{width: 30 }
    }
    
    TableView {
        id: tableView
        model: listModel
        property var titles: somethingDynamic
        property var curTitles: {
            var t=[]
            for(var i=0;i=0;i--){
                if(titles.indexOf(curTitles[i])==-1){
                    removeColumn(i)
                }
            }
        }
    }
    

    }

    It also correctly updates drag-drop-reordered columns.

提交回复
热议问题