简体   繁体   中英

QML - Shape Type, Property data has no method for removing Entries?

For my application I am creating some dynamic lines to show them on screen. I got tried creating the lines as in this example from the qt documentation:

https://doc.qt.io/archives/qt-5.10/qtquick-shapes-content-interactive-qml.html

In this example the shapepath is added into the data property of shape via:

shape.data.push(p);

However I want to remove something from this list but neither pop() or splice work. Is there a way to remove items from the data list property of Shape?

In the qt doc, not even the push method was actually mentioned.

The data property in Shape is not a JS array and is quite limited.

According to the documentation :

Note that objects cannot be individually added to or removed from the list once created; to modify the contents of a list, it must be reassigned to a new list.

So, you have to create a new list without the item you want to remove:

function removeFromShapeAt(index) {
            var d = []
            for (var i = 0; i !== shape.data.length; ++i) {
                if (i !== index) {
                    d.push(shape.data[i])
                }
            }
            shape.data = d
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM