https://bugs.kde.org/show_bug.cgi?id=480594

--- Comment #15 from fanzhuyi...@gmail.com ---
The general problem seems to be that scrollviews cannot correctly handle items
that dynamically resize based on their index...

Here is a more extreme example where the topPadding is a function of index:
(type 123 into the search and you can see the problem)

```
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import mysearch

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    ListModel {
        id: listModel
    }
    Component.onCompleted: {
        for (var i = 0; i < 1000; i++) {
            listModel.append({display: "Item " + i})
        }
    }
    // Column layout
    ColumnLayout {
        anchors.fill: parent
        // search box
        TextField {
            id: searchBox
            Layout.fillWidth: true
            Layout.fillHeight: false
            placeholderText: "Search"
        }
        ScrollView {
            Layout.fillWidth: true
            Layout.fillHeight: true
            ListView {
                id: listView
                // Layout.fillWidth: true
                // Layout.fillHeight: true
                model: CustomProxyModel {
                    sourceModel: listModel
                    filter: searchBox.text
                }
                clip: true
                delegate: ItemDelegate {
                    id: controlRoot
                    text: model.display
                    width: listView.width
                    topPadding: (index % 10) * 10
                }
            }
        }
    }
}
```

and 
```
#pragma once

#include <QSortFilterProxyModel>
#include <QtQml/qqmlregistration.h>

class CustomProxyModel : public QSortFilterProxyModel {
    Q_OBJECT
    QML_ELEMENT
    Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
public:
    CustomProxyModel(QObject *parent = nullptr)
        : QSortFilterProxyModel(parent) {}

    QString filter() const { return m_matchString; }
    void setFilter(const QString &s) {
        if (m_matchString == s)
            return;

        m_matchString = s;
        invalidateFilter();
    }

    bool filterAcceptsRow(int sourceRow,
                          const QModelIndex &sourceParent) const override {
        const auto index = sourceModel()->index(sourceRow, 0, sourceParent);
        if (!index.isValid())
            return false;
        const auto &str = index.data().value<QString>();
        bool accepted = str.contains(m_matchString);
        return accepted;
    }

Q_SIGNALS:
    void filterChanged();

private:
    QString m_matchString;
};
```

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to