aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/doc/snippets/qtquickcontrols-headerviewdelegate-custom.qml
blob: 7787475ec500e2674a23ac361fd9962bdc0d2de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick
import QtQuick.Controls

ApplicationWindow {
    width: 580
    height: 390
    visible: true

    HorizontalHeaderView {
        id: horizontalHeaderView
        anchors.left: parent.left
        anchors.leftMargin: verticalHeaderView.width
        anchors.right: parent.right
        anchors.top: parent.top
        model: ["Name", "Address", "Quant"]

        //! [horizontal-delegate]
        delegate: HorizontalHeaderViewDelegate {
            id: horizontalDelegate

            required property int index
            required property string modelData

            //! [horizontal-background]
            background: Rectangle {
                height: horizontalDelegate.height
                color: columnCheckBox.checked ? palette.highlight : palette.base
                radius: 8
            }
            //! [horizontal-background]

            //! [horizontal-contentItem]
            contentItem: Item {
                implicitWidth: columnCheckBox.implicitWidth * 2
                implicitHeight: 40

                CheckBox {
                    id: columnCheckBox
                    anchors.centerIn: parent
                    text: horizontalDelegate.modelData
                    Component.onCompleted: checked = horizontalDelegate.index === 1
                }
            }
            //! [horizontal-contentItem]
        }
        //! [horizontal-delegate]
    }

    VerticalHeaderView {
        id: verticalHeaderView
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.top: parent.top
        anchors.topMargin: horizontalHeaderView.height
        model: 6

        //! [vertical-delegate]
        delegate: VerticalHeaderViewDelegate {
            id: verticalDelegate

            required property int index

            //! [background]
            background: Rectangle {
                height: verticalDelegate.height
                color: palette.base
                border.width: rowCheckBox.checked ? 2 : 0
                border.color: palette.highlight
                radius: 8
            }
            //! [vertical-background]

            //! [vertical-contentItem]
            contentItem: Item {
                implicitWidth: rowCheckBox.implicitWidth * 2
                implicitHeight: 40

                CheckBox {
                    id: rowCheckBox
                    anchors.centerIn: parent
                    text: verticalDelegate.index + 1
                    Component.onCompleted: checked = verticalDelegate.index % 3 === 0
                }
            }
            //! [vertical-contentItem]
        }
        //! [vertical-delegate]
    }
}