1

この例のような QAbstractListModel に基づいて ListView モデルを作成しました。問題は、私の ListView がすべての行を表示するのではなく、最初に表示されている行のみを表示することです。そのため、下にスクロール (またはフリック) すると、黒いスペースしかありません。ListView には count == 0 がありますが、10 個の要素を追加したので、count == 10 になるはずです。

私のクラスには、モデルrowCountを更新するために必要なメソッドが含まれています

// needed as implementation of virtual method
int rowCount(const QModelIndex & parent) const {
    return standings.size();
}
int rowCount() {
    return standings.size();
}

void addStanding(const Standing &st) {
    beginInsertRows(QModelIndex(), rowCount(), rowCount());
    qDebug() << "row cnt: " << rowCount();
    standings << st;
    endInsertRows();
}

ListView モデルも更新します

rootContext = (QDeclarativeContext*)(viewer->rootContext());
rootContext->setContextProperty("myModel", &sm);

QML コード

ListView {
            id: raceList
            objectName: "standingList"
            y: header.height
            width: parent.width
            height: parent.height - header.height
            clip: true
            model: myModel
            delegate: rowComp
        }
        Component {
            id: rowComp
            SessionRowDelegate { }
        }

また、これは静的モデルでうまく機能することにも言及したいと思います。 ユーザーに表示されている場合だけでなく、ListViewにすべてのアイテムを常に表示させる方法は?

セッション行デリゲート

Rectangle {
  id: rowbg
  width: parent.width
  height: 34 * (1 + (parent.width - 360) * 0.002)

  // contains other elements with height not exceeding rowbg's height
  // ...
}
4

2 に答える 2

0

ListViewは、現在表示されている要素と、スクロール時に表示されるように事前にレンダリングされているいくつかの要素のみをレンダリングします。デフォルトの実装では、パフォーマンス上の理由から、それらすべてがレンダリングされるわけではありません。リストのサイズへの参照は、ListView自体ではなくモデルオブジェクトを参照する必要があります。

于 2013-03-19T17:29:52.243 に答える