Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAbstractListmodel / ListView manual positioning



  • In a ListView in qml, which uses the data model from a QAbstractListModel, I am trying to position the items (Rectangles) manually with data from the Model. This works in the beginning when I add the items but when I delete a ListItem the items get shifted upwards?
    This is the qml:
    ListView {
    id: ces_cal_markers_list
    objectName: "ces_cal_markers_list"
    anchors.left: ces_ftuc_img.left
    anchors.top: ces_ftuc_img.top
    x: grid_x
    y: grid_y
    z: 2
    interactive: true
    width: ces_ftuc_img.width
    height: ces_ftuc_img.height
    // orientation: ListView.Vertical
    model: ces_ftuc_service

        populate: Transition {
            id: dispTrans
            NumberAnimation { properties: "y"; duration: 1000 }
        }
    
        delegate:
            Rectangle {
                objectName: calib_id
                width: 30;
                height: 30;
                radius: width/2
                x: calib_x*ces_ftuc_img.width
                anchors.top: parent.top
                anchors.topMargin: calib_y*ces_ftuc_img.height
                color: calib_color; opacity: 0.3; border{color: "black"; width: 3 }
            }
    }
    

    deleting in subclass of QAbstractListModel in python:
    def delete_calib_sample(self, row):
    self.beginRemoveRows(QModelIndex(), row, row)
    del self.calib_samples[row]
    self.endRemoveRows()

    calib_x, calib_y are the values of the list model used for positioning. Someone has an idea why the items shift after deleting an item or how I can override the automatic positioning of ListViews?
    thanks in advance


Log in to reply