Remove drawed lines with Repeater on ComboBox value changed
This is the code to repeatedly dray lines on increasing the value on a ComboBox. But how can I delete the number of lines on decreasing this value?
main.qml
Code:
ComboBox {
id: combo
editable: false
model: ListModel {
id: numoflines
ListElement { text: "1"; color: "Black" }
ListElement { text: "2"; color: "Black" }
ListElement { text: "3"; color: "Black" }
ListElement { text: "4"; color: "Black" }
ListElement { text: "5"; color: "Black" }
ListElement { text: "6"; color: "Black" }
ListElement { text: "7"; color: "Black" }
}
onAccepted: {
if (combo.find(currentText) === -1) {
model.append({text: editText})
currentIndex = combo.find(editText)
}
}
onCurrentTextChanged: {
Global.numoflines = parseInt(currentIndex) + 1;
console.log(Global.numoflines);
Qt.createComponent("Analysis.qml").createObject(parent), {x: 100, y: 200};
}
}
Analysis.qml:
Code:
Rectangle {
id: base;
x: 50;
y: 480;
Column {
spacing: -12;
Repeater {
model: Global.numoflines;
delegate: Rectangle {
width: 800;
height: 1;
//color: "white";
border { width: 1; color: "black" }
radius: 3;
}
}
}
}
Re: Remove drawed lines with Repeater on ComboBox value changed
The repeater will always create as many element as its model says.
Since your model is a simple number, just decrement that number.
Cheers,
_
Re: Remove drawed lines with Repeater on ComboBox value changed
Once some number of lines is drawn, they will not be deleted when a smaller number of lines is given to the model. So how to delete them and start drawing again?
Re: Remove drawed lines with Repeater on ComboBox value changed
A Repeater that operates on a primitive model, a number or a list, will always recreate the number of delegates for the current model's count.
I.e. if the number changes from 1 to 2, it will delete all delegates and create 2.
If the number changes from 2 to 1, it will delete all delegates and create 1.
In your code the most puzzlng thing is why you create a new additional Analysis component every time the combobox changes.
Cheers,
_
Re: Remove drawed lines with Repeater on ComboBox value changed