PDA

View Full Version : Force re-creation of a QML object



sedi
27th October 2017, 16:04
Hi,
is it possible to force the re-creation of a QML item (here: TableView)?

For a TableView (QuickControls 1.4), I use the resource property in the way shown below (shortened).

When I want to change the content of a header, this is not being updated/displayed. Of course, my model emits:

emit this->headerDataChanged(Qt::Horizontal,0,999);

I have tried binding in line 18 of the biggest code block :

"title": Qt.binding(function() { return tableModel.columnHeaderName(role) }),
Unfortunately, "role" is always the highest number, not the respective appropriate one.

Calling update() does not help, toggling the visible property neither, even setting the model to undefined and back.
Can I trigger the creation process somehow? Or is there a different way to force it into diplaying a header change after creation?

Any help appreciated!
Cheers,
Sebastian

This is the (partial) code:

resources: {
var roleList = tableModel ? tableModel.userRoleNames : 0
var temp = []
var columnComponent

for(var i=0; i<roleList.length; i++) {
var role = roleList[i]
(!tableModel.isColumnHidden(role)) {
if
var columnHeaderName = tableModel.columnHeaderName(role)
if (tableModel.columnTypeName(role) === "QDate") {
columnComponent = columnComponentDate;
}
if (columnComponent) {
temp.push(columnComponent.createObject(
dynamicTableViewBasis, {
"role": role,
"title": columnHeaderName,
"width": tableModel.columnInitialWidth(role)
}))
}
}
}
return temp
}



As actual columns, I use components like this one:



Component {
id: columnComponentDate
QQC14.TableViewColumn {
delegate: Text {
id: dateDelegate
property date dateVar: styleData.value ? styleData.value : ""
text: dateVar ? appController.dateStringShort(dateVar) : ""
}
}
}

--
http://www.classintouch.de - Tablet-Software für Lehrer

sedi
10th November 2017, 22:14
The solution for me: putting the stuff in a loader. When I want to recreate the table, I just set the loader's source to "" and back.