Repeater with QAbstractListModel: Repeater does not update
-
Hi,
I am doing a plotting library. For this I made a QQuickItem which exposes a
QAbstractListModel
for the ticks of the axis to qml. Now I have a problem with drawing the ticks and labels, which I want to do using a repeater:Item{ id: root property int tickLength: 5 property int tickWidth: 1 anchors.fill: parent visible: true property var tickModel: plot.xTickModel Repeater { model: tickModel Rectangle{ height: tickLength width: tickWidth x: model.PositionRole y: parent.height-height visible: true color: "black" border.width: 2 } } Repeater { model: tickModel Text { text: PositionLabelRole x: PositionRole-width/2-tickWidth/2.0 y: parent.height+8 font.pixelSize: Style.fontSizeAxisLabel } }
However, nothing is drawn on the screen. Outside, the repeater, I tested that every time the ticks are updated
console.log("tickmodel",xAxis.tickModel.data(xAxis.tickModel.index(1,0),256))
is giving the correct results. So What am I doing wrong here?
-
What I found out so far:
The repeater never seems to call the data function of my model. Here is my setTicks Function in case the signals I emit there are relevant.:void TickModel::setTicks(std::vector<double> &pos,std::vector<QString> &labels) { beginRemoveRows(QModelIndex(),0,_tickPos.size()-1); _tickPos.clear(); _tickLabels.clear(); endRemoveRows(); beginInsertRows(QModelIndex(), 0, _tickPos.size()-1); _tickPos = std::move(pos); _tickLabels = std::move(labels); endInsertRows(); }
Is there something I need to do to get the repeater updated? Or is the problem, that I made the model available to qml as a
Q_PROPERTY
(see https://forum.qt.io/topic/104303/can-i-expose-a-c-model-as-q_property/6) and have no notify signal? -
@maxwell31 said in Problem using Repeater with QAbstractListModel:
beginInsertRows(QModelIndex(), 0, _tickPos.size()-1);
This should have been
pos
noat_tickPos
, now it works