Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

TableView & Dynamic columns creation

$
0
0
Hello Friends. I have a doubt regarding dynamic objects creation for a QML TableView ( QtQuick Controls) Is it possible to insert a new column on TableView? Documentation describes that it has to be an instance of TableViewColumn, but for my application the ListModel changes in runtime so the TableView should do so as well. It seems that the model is not visible to the created object, so the column is added but empty. Thanks. Here is a code example:     TableView{         id:idTable         x: 50         y: 50         width: 400         model: libraryModel                             // Table Data model           TableViewColumn{ role: "title"  ; title: "Title" ; width: 100 }         TableViewColumn{ role: "author" ; title: "Author" ; width: 200 }         property string strTestColumn : "import QtQuick 2.1; import QtQuick.Controls 1.0; import QtQuick.Layouts 1.0; TableViewColumn{id:idTestColumn; role:\"buyer\"; title: \"Another Column\" ; width: 100 ; Component.onCompleted: {console.log(\"#\");libraryModel.count}}"           Component.onCompleted: {               var ii= 0               //it starts at zero "0"             for( ii=0; ii < libraryModel.count;ii++)             {                 libraryModel.setProperty(ii, "buyer", "Something");                 console.log(libraryModel.get(ii).buyer + "\n");             }             idTable.addColumn(Qt.createQmlObject(idTable.strTestColumn,idTable,'firstObject'));         }       }         //Data model for Table     ListModel {        id: libraryModel        //syntax: ListElement{ <Key identifier>: <Value>; ... }        ListElement{ title: "A Masterpiece" ; author: "Gabriel" ; pages: 500; mc: "1"}        ListElement{ title: "Brilliance"    ; author: "Jens"    ; pages: 700; mc: "2"}        ListElement{ title: "Outstanding"   ; author: "Frederik"; pages: 600; mc: "3"}     }

Viewing all articles
Browse latest Browse all 4972

Trending Articles