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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.