Important: Please read the Qt Code of Conduct -

How to make cells of a grid all the same size in QML?

  • Hi everyone,

    I have been working on a UI where everything is responsive. I have a grid filled with elements.
    Even though all the elements have the same size specifications, the grid sometimes is longer on one side than the other, like in the image:

    Does anyone know how to force it to balance equally on both sides?


  • Hi,

    Could you share code of grid?

    In my project I'm using code:
    GridView {
    id: classesListGrid
    anchors.horizontalCenter: parent.horizontalCenter
    width: parent.width
    height: parent.height
    cellHeight: 45
    cellWidth: classesListGrid.width / 3
    clip: true
    model: someModel
    delegate: Item {
    width: classesListGrid.cellWidth
    height: classesListGrid.cellHeight

        //Content od every item of grid


  • Hi shav, this is my code, it does not accept cellHeight property :/

    id: controlsGridPlaceholder
    objectName: "controlsGridPlaceholder"
    Layout.fillHeight: true
    Layout.fillWidth: true
    columns: (screenOrientation === 2 || screenOrientation === 8) ? 1 : 2



Log in to reply