From 10b3bffbd21b6265a3d124f310c99fcbac2b027f Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 19 Oct 2018 11:51:39 +0200 Subject: TableView: Handle dynamic insertion of TableViewColumns correctly When inserting a TableViewColumn after the TableView is created, then it needs to be inserted into the list of columns at the specified index so that it responds correctly to things like resizeColumnsToContents() Fixes: QTBUG-58594 Change-Id: If7ff545306fe8b6616d8e016eb87e565ed40c836 Reviewed-by: Frederik Gladhorn --- src/controls/Private/BasicTableView.qml | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/controls/Private/BasicTableView.qml b/src/controls/Private/BasicTableView.qml index 2557dca7..1f846b57 100644 --- a/src/controls/Private/BasicTableView.qml +++ b/src/controls/Private/BasicTableView.qml @@ -260,6 +260,17 @@ ScrollView { if (index >= 0 && index <= columnCount && object.Accessible.role === Accessible.ColumnHeader) { object.__view = root columnModel.insert(index, {columnItem: object}) + if (root.__columns[index] !== object) { + // The new column needs to be put into __columns at the specified index + // so the list needs to be recreated to be correct + var arr = [] + for (var i = 0; i < index; ++i) + arr.push(root.__columns[i]) + arr.push(object) + for (i = index; i < root.__columns.length; ++i) + arr.push(root.__columns[i]) + root.__columns = arr + } return object } -- cgit v1.2.1