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. [SOLVED] ListView delegates and offsetting
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] ListView delegates and offsetting

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.7k 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.
  • A Offline
    A Offline
    Alcatraz
    wrote on last edited by
    #1

    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

    !http://img862.imageshack.us/img862/1811/38812146.png!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alcatraz
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on last edited by
          #4

          Well, just the normal docs on anchoring http://doc.qt.nokia.com/4.7-snapshot/qml-anchor-layout.html#anchor-layout 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 ;-)

          Cheers,
          Chris

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alcatraz
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alcatraz
              wrote on last edited by
              #6

              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 :)

              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