Я пытаюсь создать список, который можно расширить или сократить, добавляя или удаляя строки. Понять это было очень просто, но проблема в том, что ColumnLayout, похоже, не перемещает элементы в зависимости от их нового размера.
Вот минимальный код для воспроизведения проблемы
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Window 2.2
ApplicationWindow {
id: window
visible: true
width: 630
height: 891
ListModel {
id: productModel
ListElement {
description: "Test"
}
ListElement {
description: "Other test"
}
}
ListModel {
id: invoiceModel
ListElement {
description: "Factuur 6419"
}
ListElement {
description: "Factuur 6491"
}
}
ColumnLayout {
width: 500
ExpandingTable {
width: 500
model: productModel;
}
TextArea {
placeholderText: "test"
}
ExpandingTable {
width: 500
model: invoiceModel;
}
}
}
А затем файл с именем ExpandingTable.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
ListView {
id: listView
height: contentHeight
interactive: false
delegate : RowLayout {
width: parent.width;
TextField {
text: description
}
Button {
text: "-"
onClicked: {
listView.model.remove(model.index)
}
}
}
Button {
text: "+"
anchors.left: listView.right
anchors.bottom: listView.bottom
onClicked: {
listView.model.append({ description: "" })
}
}
}
Я особенно не уверен насчет линий
listView.model.remove(model.index)
а также
listView.model.append({ description: "" })
И должна ли она быть просто моделью. или фактически быть listview.model.