는 방법을 끈끈한 헤더에 대한 GridLayout 에 Flickable

0

질문

나는 GridLayout 에 의해 채워 Repeater(a TableView 에 맞지 않는 내가 필요),내부 Flickable 그래서 스크롤 할 수 있습니다.

내 GridLayout 헤더를 포함할 수 있습니 쉽게 추가하여 Texts 기 전에 내 Repeater 다음과 같다:

import QtQuick 2.0
import QtQuick.Layouts 1.12

ColumnLayout {
    width: 200
    height: 200

    Flickable {
        Layout.fillWidth: true
        Layout.preferredHeight: 200
        contentWidth: width
        contentHeight: grid.height
        clip: true

        GridLayout {
            id: grid
            columns: 3
            columnSpacing: 10

            function reparentChildren(source, target) {
                while (source.children.length) {
                    source.children[0].parent = target;
                }
            }

            // Header
            Text {
                text: "Header 0"
            }
            Text {
                text: "Header 1"
            }
            Text {
                text: "Header 2"
            }

            // Data
            Repeater {
                model: 50

                Item {
                    Component.onCompleted: grid.reparentChildren(this, grid)
                    Text {
                        text: "Column 0, %1".arg(modelData)
                    }
                    Text {
                        text: "Column 1, %1".arg(modelData)
                    }
                    Text {
                        text: "Column 2, %1".arg(modelData)
                    }
                }
            }
        }
    }
}

그러나 나는 나의 헤더를"끈끈한"/"frozen",즉 유지 보이는 경우 스크롤 Flickable. 를 만들 수 있었 내 헤더외 Flickable,그러나 GridLayout 지 않는 나에게 최종 행 크기,그래서 내가 수치 헤더니다.

qml qt
2021-11-23 10:31:17
1

최고의 응답

0

그것의 비트 해키지만,저는 솔루션을 찾았습니다.

첫째,만들기를"거짓"헤더 Items. 할 수 있게 설정들 Layout.minimalWidth 야의 폭 헤더를 텍스트할 경우 필요합니다.

그런 다음,앞의 항목 Flickable 을 만들고 헤더가 있는지 확인 그것은 수평으로 정렬과 그리드,그리고 요소를 배치를 사용하는 x 의 값을 헤더가 있습니다.

마지막으로,설정 부정적인 여백에 Flickable 을 제거하는 불필요한 행 추가해 더미 헤더가 있습니다.

fillWidth: true 에 거짓고 다음 설정 width 각각의 헤더가 항목이 있지만,단점은 테이블을 수정 열의 폭입니다.

import QtQuick 2.0
import QtQuick.Layouts 1.12

ColumnLayout {
    width: 200
    height: 200

    // Header
    Item {
        Layout.minimumHeight: childrenRect.height
        Layout.fillWidth: true
        Text {
            id: header0
            x: headerDummy0.x
            anchors.top: parent.top
            text: "Header 0"
        }
        Text {
            id: header1
            x: headerDummy1.x
            anchors.top: parent.top
            text: "Header 1"
        }
        Text {
            id: header2
            x: headerDummy2.x
            anchors.top: parent.top
            text: "Header 2"
        }
    }

    Flickable {
        Layout.fillWidth: true
        Layout.preferredHeight: 200
        contentWidth: width
        contentHeight: grid.height
        clip: true
        // Eliminate the first row, which are the dummies
        topMargin: - grid.rowSpacing

        GridLayout {
            id: grid
            columns: 3
            rowSpacing: 50
            columnSpacing: 10

            function reparentChildren(source, target) {
                while (source.children.length) {
                    source.children[0].parent = target;
                }
            }

            // Header dummies
            Item {
                id: headerDummy0
                Layout.minimumWidth: header0.implicitWidth
            }
            Item {
                id: headerDummy1
                Layout.minimumWidth: header1.implicitWidth
            }
            Item {
                id: headerDummy2
                Layout.minimumWidth: header2.implicitWidth
            }

            // Data
            Repeater {
                model: 50

                Item {
                    Component.onCompleted: grid.reparentChildren(this, grid)
                    Text {
                        text: "Column 0, %1".arg(modelData)
                    }
                    Text {
                        text: "Column 1, %1".arg(modelData)
                    }
                    Text {
                        text: "Column 2, %1".arg(modelData)
                    }
                }
            }
        }
    }
}
2021-11-23 10:31:17

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................