actual in qt5.11
it seem what glitch happens within
QAbstractItemView::rowsAboutToBeRemoved
or so...
QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
{
Q_D(QAbstractItemView);
setState(CollapsingState);
....
CollapsingState... for qlistview ???
workaround for some cases
class listviewscrollfix: public QListView{...}
void listviewscrollfix::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
// Q_D(QListView);
// // if the parent is above d->root in the tree, nothing will happen
///QAbstractItemView::rowsAboutToBeRemoved(parent, start, end);
{
//Q_D(QAbstractItemView);
setState(NoState);/// !!! CollapsingState ///main glitch reason
// Ensure one selected item in single selection mode.
QModelIndex current = currentIndex();
if (selectionMode() == SingleSelection
&& current.isValid()
&& current.row() >= start
&& current.row() <= end
&& current.parent() == parent) {
int totalToRemove = end - start + 1;
if (model()->rowCount(parent) <= totalToRemove) { // no more children
QModelIndex index = parent;
///we dont have access to some metods so skipped
// while (index != d->root && !d->isIndexEnabled(index))
// index = index.parent();
// if (index != d->root)
setCurrentIndex(index);
} else {
///we dont have access to some metods so skipped
// int row = end + 1;
// QModelIndex next;
// do { // find the next visible and enabled item
// next = d->model->index(row++, current.column(), current.parent());
// } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next)));
// if (row > d->model->rowCount(parent)) {
// row = start - 1;
// do { // find the previous visible and enabled item
// next = d->model->index(row--, current.column(), current.parent());
// } while (next.isValid() && (isIndexHidden(next) || !d->isIndexEnabled(next)));
// }
// setCurrentIndex(next);
}
}
///we dont have access to some metods & and our list not editable so skipped
// Remove all affected editors; this is more efficient than waiting for updateGeometries() to clean out editors for invalid indexes
// QEditorIndexHash::iterator i = d->editorIndexHash.begin();
// while (i != d->editorIndexHash.end()) {
// const QModelIndex index = i.value();
// if (index.row() >= start && index.row() <= end && d->model->parent(index) == parent) {
// QWidget *editor = i.key();
// QEditorInfo info = d->indexEditorHash.take(index);
// i = d->editorIndexHash.erase(i);
// if (info.widget)
// d->releaseEditor(editor, index);
// } else {
// ++i;
// }
// }
}
///we dont have access to some metods & we dont have hidden rows so skipped
// if (parent == d->root) {
// QSet<QPersistentModelIndex>::iterator it = d->hiddenRows.begin();
// while (it != d->hiddenRows.end()) {
// int hiddenRow = it->row();
// if (hiddenRow >= start && hiddenRow <= end) {
// it = d->hiddenRows.erase(it);
// } else {
// ++it;
// }
// }
// }
// d->clear();//???
// d->doDelayedItemsLayout();
}
or just
void listviewscrollfix::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end){}
and
bool SomeListModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid())
return false;
...
for (int i = 0; i != count; ++i){
...
beginRemoveRows(parent, row, row);
someitemcontainer.removeAt(row);//for small listst it will be ok 1 by 1
endRemoveRows();
dataChanged(index(row),index(row));//scroll glitch workaround...dont ask why so...//for update scrollbar max value
...
}
return true;
}