How to add items to a listview from the user perspective

I wanted to know how could I make it for a user to add items to my listview, so that his events could stay there, and later move to a database. beneath it the code I've for my listview now i want know if a user with a text-box could add new items to

Rectangle {
y: 170
x: 100
width: rootId.width
height: rootId.height
z: 1
color: "transparent"
ListModel { id: nome_eventoModel ListElement { nome_evento: "festival multi cultural"; tipo_evento: "Magos" } ListElement { nome_evento: "workshop multimedia"; tipo_evento: "IDAS" } ListElement { nome_evento: "Congresso jovem"; tipo_evento: "CML" } ListElement { nome_evento: "Workshop Ubuntu mobile"; tipo_evento: "Departamento Ubuntu IDAS" } ListElement { nome_evento: "Workshop trabalhar com QML"; tipo_evento: "Departamento Ubuntu IDAS" }
}
Component { id: nome_eventoDelegate Text { text: nome_evento; font.pixelSize: 24 anchors.left: parent.left anchors.leftMargin: 2 }
}
ListView { y: 10 anchors.leftMargin: -65 anchors.topMargin: -37 anchors.rightMargin: -169 anchors.bottomMargin: 22 layoutDirection: Qt.LeftToRight anchors.fill: parent model: nome_eventoModel delegate: nome_eventoDelegate focus: true highlight: Rectangle { color: "#F08080" width: parent.width } section { property: "tipo_evento" criteria: ViewSection.FullString delegate: Rectangle { color: "#b0dfb0" width: parent.width height: childrenRect.height + 4 Text { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent font.pixelSize: 16 font.bold: true text: section } } }
}
Component { id: petdelegate Text { id: label font.pixelSize: 24 text: if (index == 0) label.text = type + " (default)" else text: type }
}

}

1 Answer

you can use ListModel.append()

add two TextField elements (one for nome_evento and the other for tipo_evento) and a Button

So when you click on the button it should append what you wrote on the textfields

Button{ onClicked : if(texField1.text !== "" && texField2.text !== ""){ nome_eventoModel.append({"nome_evento": texField1.text, "tipo_evento": texField2.text}) }
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like