<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Help with GridView]]></title><description><![CDATA[<p dir="auto">I am having some trouble with <code>GridView</code>. I have a 1024 (width) screen. I want to have three <code>Rectangles</code> that will fill their <code>Cell</code> be evenly spaced on the screen like so:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/57359f07-0265-44fc-a41e-bbb706a53b0b.png" alt="untitled(1).png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Keep in mind I made the above image in mspaint so just pretend it's perfect XD (screen is red)</p>
<p dir="auto">How can I do this using <code>GridView</code>? I have tried all sorts of things but I can't seem to get it right. The best I have managed to do is to create cell's which are larger than the <code>Rectangles</code> within them. That on top of decreasing the width of the <code>GridView</code> allows me to space them out evenly but only with respect to one another and not the parent of the <code>GridView</code>. Here's my basic code:</p>
<pre><code>      GridView
      {
        id: gridView
        height: parent.height
        width: parent.width
        model: 3
        cellWidth: 150
        cellHeight: 150

        delegate: Rectangle
        {
          height: 150
          width: 150
          color: "blue"
        }
      }
</code></pre>
]]></description><link>https://forum.qt.io/topic/115019/help-with-gridview</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 01:37:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/115019.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 May 2020 16:33:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Help with GridView on Wed, 20 May 2020 18:44:43 GMT]]></title><description><![CDATA[<p dir="auto">Ah, okay, then maybe something like this:</p>
<pre><code>GridView
    {
        id: gridView
        anchors.fill: parent
        model: 3
        cellWidth: width/count
        cellHeight: cellWidth

        delegate: Rectangle {
            width: gridView.cellWidth
            height: gridView.cellHeight
            color: "red"

            Item {
                width: 150
                height: 150

                anchors.margins: 20
                anchors.centerIn: parent

                Rectangle {
                    anchors.fill: parent
                    color: "blue"
                }
            }
        }
    }
</code></pre>
]]></description><link>https://forum.qt.io/post/595953</link><guid isPermaLink="true">https://forum.qt.io/post/595953</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Wed, 20 May 2020 18:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to Help with GridView on Wed, 20 May 2020 19:08:57 GMT]]></title><description><![CDATA[<p dir="auto">YES! This is exactly what I wanted, well almost, I altered the margins so that (given you only have an odd number of items per row) everything will be spaced perfectly evenly:</p>
<pre><code>  Component
  {
    id: girdViewComponent

    Item
    {
      //This item is 1024 wide
      id : gridViewContainer

      GridView
      {
        id: gridView

        anchors.fill: parent
        cellHeight: 150
        cellWidth: parent.width/count

        model: 3

        delegate: Item
        {
          width: gridView.cellWidth
          height: gridView.cellHeight

          Rectangle
          {
            anchors.fill: parent

            anchors.topMargin: 10
            anchors.bottomMargin: 10
            anchors.leftMargin: index % 2 !== 0 ? 0 : 10
            anchors.rightMargin: index % 2 !== 0 ? 0 : 10

            Rectangle
            {
              width: 10
              height: 10
              anchors.centerIn: parent
              color: "red"
            }
          }
        }
      }
</code></pre>
]]></description><link>https://forum.qt.io/post/595955</link><guid isPermaLink="true">https://forum.qt.io/post/595955</guid><dc:creator><![CDATA[RobM]]></dc:creator><pubDate>Wed, 20 May 2020 19:08:57 GMT</pubDate></item><item><title><![CDATA[Reply to Help with GridView on Wed, 20 May 2020 18:44:43 GMT]]></title><description><![CDATA[<p dir="auto">Ah, okay, then maybe something like this:</p>
<pre><code>GridView
    {
        id: gridView
        anchors.fill: parent
        model: 3
        cellWidth: width/count
        cellHeight: cellWidth

        delegate: Rectangle {
            width: gridView.cellWidth
            height: gridView.cellHeight
            color: "red"

            Item {
                width: 150
                height: 150

                anchors.margins: 20
                anchors.centerIn: parent

                Rectangle {
                    anchors.fill: parent
                    color: "blue"
                }
            }
        }
    }
</code></pre>
]]></description><link>https://forum.qt.io/post/595953</link><guid isPermaLink="true">https://forum.qt.io/post/595953</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Wed, 20 May 2020 18:44:43 GMT</pubDate></item><item><title><![CDATA[Reply to Help with GridView on Wed, 20 May 2020 18:30:59 GMT]]></title><description><![CDATA[<p dir="auto">I have been able to get that but what I need to do is now take that <code>GridView</code> and center it within the <code>Window</code>, how might I do that? For instance here is what I have:</p>
<pre><code>    Item
    {
      //This item is 1024 wide
      id : gridViewContainer 


      GridView
      {
        id: gridView

        anchors.fill: parent
        cellHeight: 150
        cellWidth: 150

        model: 3

        delegate: Item
        {
          width: gridView.cellWidth
          height: gridView.cellHeight


          Rectangle
          {
            anchors.fill: parent
            color: "blue"
            anchors.margins: 20
          }
        }
      }
</code></pre>
<p dir="auto">Here is what this actually looks like (took a screenshot) and cropped it:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/4ef01788-b1d9-41e7-a248-82d97f245d72.png" alt="bad.png" class=" img-fluid img-markdown" /><br />
and here is what I want (edited the above image in mspaint):<br />
<img src="https://ddgobkiprc33d.cloudfront.net/eeebb0bd-8455-4c05-92e4-61970709c9f4.png" alt="good.png" class=" img-fluid img-markdown" /><br />
Does this make sense?</p>
]]></description><link>https://forum.qt.io/post/595951</link><guid isPermaLink="true">https://forum.qt.io/post/595951</guid><dc:creator><![CDATA[RobM]]></dc:creator><pubDate>Wed, 20 May 2020 18:30:59 GMT</pubDate></item><item><title><![CDATA[Reply to Help with GridView on Wed, 20 May 2020 17:21:53 GMT]]></title><description><![CDATA[<p dir="auto">anchors can do this:</p>
<pre><code>import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12

Window {
    visible: true
    width: 450
    height: 450
    title: qsTr("Grid View Spacing")

    GridView
    {
        id: gridView
        height: parent.height
        width: parent.width
        model: 3
        cellWidth: 150
        cellHeight: 150

        delegate: Rectangle {
            width: gridView.cellWidth
            height: gridView.cellHeight
            color: "red"

            Item {
                anchors.fill: parent
                anchors.margins: 20

                Rectangle {
                    anchors.fill: parent
                    color: "blue"
                }
            }
        }
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/595937</link><guid isPermaLink="true">https://forum.qt.io/post/595937</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Wed, 20 May 2020 17:21:53 GMT</pubDate></item></channel></rss>