Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick
- import QtQuick.Window
- import QtQuick.Controls
- Window {
- id: root
- width: 240
- height: 300
- visible: true
- title: qsTr("Test")
- ListModel {
- id: listModel
- ListElement {
- txt: "Item 1"
- }
- }
- ListView {
- id: listView
- anchors.fill: parent
- clip: true
- model: listModel
- reuseItems: true
- topMargin: root.height / 2
- bottomMargin: root.height / 2
- delegate: TextArea {
- id: delegate
- required property int index
- required property string txt
- width: root.width
- text: txt
- onCursorPositionChanged: {
- listView.positionViewAtIndex(delegate.index, ListView.Center);
- }
- Keys.onReturnPressed: {
- listModel.append({txt: "Item " + (listModel.count + 1)});
- }
- Keys.onPressed: (event) => {
- if (event.key === Qt.Key_Backspace) {
- if (delegate.index > 0) {
- listView.positionViewAtIndex(delegate.index - 1, ListView.Center);
- listView.itemAtIndex(delegate.index - 1).forceActiveFocus();
- }
- listModel.remove(delegate.index);
- }
- }
- ListView.onAdd: {
- delegate.forceActiveFocus();
- delegate.cursorPosition = delegate.text.length;
- listView.positionViewAtIndex(delegate.index , ListView.Center);
- }
- }
- ScrollBar.vertical: ScrollBar {}
- }
- }
Add Comment
Please, Sign In to add comment