Sandy
Sandy

Reputation: 143

How to set background for qml gridview in Qt

How to set background of gridview from QML file.

Upvotes: 3

Views: 15328

Answers (2)

JuliusG
JuliusG

Reputation: 2371

Nest the grid view in a Rectangle and make the delegates of the GridView elements transparent:

    Rectangle {
      color: "red"
      GridView {
        delegate: Rectangle {
          color: "transparent"
        }
      }
    }

Upvotes: 5

xk0der
xk0der

Reputation: 3680

In QML you can compose complex objects by including/nesting widgets/elements within each other.

So for including an image inside a Widget, in your case the GridView, just nest an Image element, inside GridView Element or it's sub elements as required.

GridView {
    width: 800
    height: 600
    Image: {
       source: "some-image.png"
    }
}

The documentation for GridView has similar and better examples - http://doc.qt.digia.com/4.7-snapshot/qml-gridview.html#example-usage

Also look out for the anchors attribute, which will help you position the image in the parent Element, or otherwise.

Documentation for Image element is available here: http://doc.qt.digia.com/latest/qml-image.html

Upvotes: 2

Related Questions