과 비슷한 QAbstractListModel을 기반으로 ListView 모델을 만들었습니다. 문제는 내 ListView가 모든 행을 표시하지 않지만 초기 표시 가능한 행만 표시한다는 것입니다. 그래서 내가 스크롤 할 때 (또는 가볍게 치기) 검은 공간 만 뚫습니다. ListView에는 count == 0이 있지만 10 개의 요소를 추가 했으므로 count == 10이어야합니다.QML ListView 개수가 0이고 일부 행만 표시됩니다.
내 클래스는 나는 또한 ListView를 모델 나는 또한 언급하고 싶은
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 { }
}
rootContext = (QDeclarativeContext*)(viewer->rootContext());
rootContext->setContextProperty("myModel", &sm);
QML 코드를 업데이트
// 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();
}
모델 rowCount의를 갱신하는 데 필요한 mothods을 포함 이것은 정적 모델로 잘 동작합니다. ListView는 모든 항목을 항상 표시 할뿐만 아니라 사용자에게 표시 할 수있을뿐만 아니라?
SessionRowDelegate는
Rectangle {
id: rowbg
width: parent.width
height: 34 * (1 + (parent.width - 360) * 0.002)
// contains other elements with height not exceeding rowbg's height
// ...
}
QML 코드를 게시 할 수 있습니까? –
SessionRowDelegate는 어떻게 생겼습니까? 가장 중요한 점은 목록보기의 모든 행을 균일 한 높이로 유지해야한다는 것입니다. 그렇지 않으면 ListView가 제대로 작동하지 않습니다. – sebasgo
예, SessionRowDelegate의 높이가 설정됩니다. 목록보기의 모든 행에는 균일 한 높이가 있습니다. – dbow