Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Repeater with QAbstractListModel: Repeater does not update
Qt 6.11 is out! See what's new in the release blog

Repeater with QAbstractListModel: Repeater does not update

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by maxwell31
    #1

    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?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by maxwell31
      #2

      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?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        maxwell31
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          @maxwell31 said in Problem using Repeater with QAbstractListModel:

          beginInsertRows(QModelIndex(), 0, _tickPos.size()-1);

          This should have been pos noat _tickPos, now it works

          Gojir4G 1 Reply Last reply
          0
          • M maxwell31

            @maxwell31 said in Problem using Repeater with QAbstractListModel:

            beginInsertRows(QModelIndex(), 0, _tickPos.size()-1);

            This should have been pos noat _tickPos, now it works

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by Gojir4
            #5

            @maxwell31 As you are reseting the whole content of your model, you can call begineResetModel() and endResetModel() respectively at start and end of your function setTicks().

            1 Reply Last reply
            2
            • M Offline
              M Offline
              maxwell31
              wrote on last edited by
              #6

              Thank you for the suggestion, I will change this

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved