Important: Please read the Qt Code of Conduct -

[SOLVED] ListView delegates and offsetting

  • hello again Qt-Project

    i have a horizontal ListView x: 1240 y: 250 and my delegate is x: 135 y: 207

    now i know that my delegate can fit inside my listview 8 times with a spacing of 20

    so what im trying to do is if model.count < 8 then center the items within the ListView i been trying to do some math to try and figure out the solution but have not found one

    if there is an easier way of doing this please help thanks

    so far i been trying to position delegate x: (someMathHere) to get the correct position

    see image for example


  • You can use an intermediate container item, and just anchor its horizontal centre to its parent's horizontal centre, if the count is less than 8 or whatever your condition is.

  • Would you have any examples on how to do that? Or where I could get some information on doing that

  • Well, just the normal docs on anchoring have information on the different anchor points. I'm not sure if my suggestion is useful in your case, however, simply because I'm not too familiar with listview or delegates. But it might be possible to have the listview itself be anchored at the horizontal centre of a container item, and then have its horizontal size be ((delegateSize + spacing) * Math.min(8, model.count)) or whatever (ie, the listview is always as small as possible, and the listview itself is anchored in the centre.

    The other possibility is that my suggestion won't work for views/delegates, and if so I apologise ;-)


  • i need the 1240 width for the flickable area sorry if i forgot to mention that

  • i solved this issue like so

    @ property int xx: 8 %iconModel.count
    property int yy: 155

          x: if(iconModel.count < 9){(yy * xx) /2 }else{ 0 }  @

    so the remainder of what iconmodel.count is in my case was 7 with a remainder of 1 * the space required and cut that in half gives me my position :)

Log in to reply