QAbstractListModel resetModel lags



  • I use QAbstractListModel with my ListView. The delegate of the ListView consist of 19 Rectangles with Text. When I reset the model, it takes about 300ms to recreate 1 delegate item. If there are 20-30 items in the new model data, it takes 5-6 sec. If I reset the model 2-3 times, it crashes with an error at this line:
    endResetModel();
    Is there a faster way to update a ListView content and how can I fix this crash problem?
    Here is my minimized code:
    @

    QVariant TargetsModel::data(const QModelIndex & index, int role) const {
    return QVariant(0); //does not matter
    }
    void TargetsModel::setModel(int ship, TableData &model)
    {
    beginResetModel();
    m_data.replace(model); //Just replace old vector
    endResetModel();
    }
    @

    ListView delegate:

    @
    Column {
    id: column
    property double firstblockwidth: Math.round(column.width/17*7)
    width: parent.width
    spacing: 0

    Row {
        z: 20
        spacing: 0
        CustomNumberField {
            width: Math.round(column.firstblockwidth/3)
            value:  complexnum
        }
        CustomNumberField {
            width: Math.round(column.firstblockwidth/3*2)-x
            value:  mcnum
        }
        CustomNumberField {
            width: Math.round(column.width/17*10.5)-x
            value: vip
        }
        CustomNumberField {
            width: Math.round(column.width/17*13)-x
            value: bearing
        }
        CustomNumberField {
            width: Math.round(column.width)-x
            value: distance/1000.0
        }
    }
    

    }
    @

    CustomNumberField:

    @
    Rectangle {
    id: numberfield
    property alias font: textfield.font
    property var value: 0
    property real minimumValue: 0
    property real maximumValue: 0
    property real decimals: 2

    property string background: "#2f2f2f"
    
    property bool edited: false
    width: 25
    height: 25
    color: "#2f2f2f"
    border.width: 1
    border.color: "#6d6d6d"
    Text {
        id: textfield
        font.pointSize: 10
        font.family: arialFont.name
        anchors.fill: parent
        anchors.margins: 2
        verticalAlignment: Qt.AlignVCenter
        text: numberfield.value
        color: "white"
    }
    

    }
    @

    Due to the non-standard shape of the delegate I can't use TableView (2 rows with different number of items)



  • Hi, did you try to notify view of changes (beginInsertRows()/endInsertRows(), beginMoveRows()/endMoveRows(), etc.) instead of resetting whole model?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.