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. Center GridView Rows on screen
Qt 6.11 is out! See what's new in the release blog

Center GridView Rows on screen

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • D Offline
    D Offline
    Duff
    wrote on last edited by
    #1

    Suppose I have a GridView whose width takes up the whole screen. I want the item rows to be centered on the screen. How do I do it?

    --Duff

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Can you show what you have tried and what was the effect and how you actually want it to look ?
      Is anchors.centerIn you looking for ?

      157

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Duff
        wrote on last edited by
        #3

        Hi p3cO,

        Normally, anchors.centerIn would do the job but there may be a situation where the GridView is not filled with items all the way to the edge of its container (depending on number of items available or differences in available screen width). In that case centering the GridView does not actually center the items contained therein.
        I was hoping the GridView implementer's would have found a nice solution for that. Turns out, I think I will have to use a little math and determine what the actual combined width of the items will amount to for a single row of the grid and then set the width of the GridView to that before centering.
        If anyone has a more elegant solution I would be glad to hear it.

        thanks

        BD

        --Duff

        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