Are ListView sections stylable?
Unsolved
QML and Qt Quick
-
I would like to create a Listview with sections, however, I would like to apply a Material style elevation to the sections.
I know I can add it to the separate items like this:
import QtQuick import QtQuick.Controls import QtQuick.Controls.Material ApplicationWindow { visible: true minimumWidth: 600 minimumHeight: 500 ListModel { id: item_list_model ListElement { category: "a" name: "Apple" } ListElement { sender: "a" subject: "Banana" } ListElement { sender: "x" subject: "Laptop" } } ListView { anchors.fill: parent model: item_list_model delegate: Pane { Material.elevation: 4 Label { text: model.name } } section.property: 'category' section.criteria: ViewSection.FullString section.delegate: Label { text: section } } }
However, I cannot find the option to add style to the section containers (like different background color or
Material.elevation
).I considered:
- putting a ListView inside a ListView. However, I read it that it is not stable, and might break easily.
- using delegates for the sections and inside them using a
Repeater
for the items, but it also breaks some useful functionality - likesnapMode
, to snap to individual items.
Is it possible to style sections, or do I need to create my own custom ListView?
-
@MrMeszaros you can style it anyway you want to. just add wrapper and style it to your liking:
section.delegate: Rectangle{ width: parent.width height: childrenRect.height color: "red" required property string section Text { anchors.horizontalCenter: parent.horizontalCenter text: parent.section font.bold: true color: "blue" font.pointSize: 13 } }