Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView: leftMargin and rightMargin properties do not work

Tags:

qt

qml

qtquick2

It works okay for the Flickable (i.e. Flickable with Grid and same Rectangles (see code below) in it).

Here's an example for GridView:

import QtQuick 2.7
import QtQuick.Controls 1.4

ApplicationWindow {
    id: rootWindow

    visible: true
    width: 300
    height: 300

    Rectangle {
        anchors.fill: parent
        color: "yellow"

        GridView {
            id: gridView
            anchors.fill: parent

            cellWidth: 50
            cellHeight: 50
            model: 54

            bottomMargin: 10
            topMargin: 10
            leftMargin: 10 // this doesn't work
            rightMargin: 10 // this doesn't work

            delegate: Rectangle {
                width: gridView.cellWidth - 1
                height: gridView.cellHeight - 1
                color: "green"
            }
        }
    }
}
like image 885
rsht Avatar asked Apr 27 '26 14:04

rsht


1 Answers

Maybe thats what you are looking for:

    ...
    GridView {
        id: gridView
        anchors {
            fill: parent
            margins: 10
        }
        clip: true

        cellWidth: 50
        cellHeight: 50
        model: 54

        delegate: Rectangle {
            width: gridView.cellWidth - 1
            height: gridView.cellHeight - 1
            color: "green"
        }
    }
    ...
like image 197
thomas Avatar answered Apr 30 '26 03:04

thomas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!