gpt4 book ai didi

c++ - Qt:从QAbstractListModel删除多行

转载 作者:行者123 更新时间:2023-12-01 14:55:13 25 4
gpt4 key购买 nike

有没有一种方法可以有效地从QAbstractListModel中删除不连续的多行?效率低下的例子:

// Single row removal
void remove (int idx) {
beginRemoveRows (noParent (), idx, idx);
// internal remove
endRemoveRows ();
}

// Remove each row by calling beginRemoveRows multiple times
void removeMultiple (const QList<QObject*> &items) {
foreach (auto item, items)
{
int idx = findIndexInternal(item);
beginRemoveRows (noParent (), idx, idx);
// internal remove
endRemoveRows ();
}
}

问候,

最佳答案

参见Qt's Model-View reference:

This sequence can be used for any structural update in lieu of the more high-level and convenient protected methods. For example, if a model of two million rows needs to have all odd numbered rows removed, that is 1 million discountiguous ranges of 1 element each. It would be possible to use beginRemoveRows and endRemoveRows 1 million times, but that would obviously be inefficient. Instead, this can be signalled as a single layout change which updates all necessary persistent indexes at once.



似乎可以使用 layoutAboutToBeChanged()layoutChanged()向基础模型发出较大的更改信号。我还没有测试过。

更新:我目前正在使用这种体系结构,并且可以解决问题。您甚至不必用信号通知行删除/添加,因为这是由布局信号处理的。

关于c++ - Qt:从QAbstractListModel删除多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45552831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com