Jhonny Pinheiro
Jhonny Pinheiro

Reputation: 328

Is it possible customize the QML TableView headerDelegate individually?

In QML TableView, is possible customize the header, using headerDelegate, but the style applied, work for all columns.

Example:

headerDelegate: Rectangle {
    height: 20
    color: "red"

    Text {
        text: styleData.value
        color: "#FFF"
        width: parent.width
        height: parent.height
        font.pointSize: 18
        minimumPointSize: 3
        fontSizeMode: Text.Fit
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
    }
}

Is it possible apply the style individually? For example: In the first column background blue and the second column background red

Or exist another way to customize the header?

Upvotes: 1

Views: 2203

Answers (1)

derM
derM

Reputation: 13691

Maybe there exist more elegant ways for the TableView in particular, but a common approach to customize delegates in general is to use the provided information.

For the basic usecase of having different colors, you can just have it:

headerDelegate: Rectangle {
    color: ["red", "blue"][styleData.column % 2]
}

For more complex things, you can make the delegate a Loader which loads different sourceComponents depending on the information you have available for the delegate.

Upvotes: 1

Related Questions