Jak stworzyć lepki nagłówek do siatki w изменяемом

0

Pytanie

Mam siatki wypełnione ekspanderem (widok tabeli nie spełnia moich potrzeb), w którym można przełączać się, żebym mógł przewijać zawartość.

Chcę, aby moja siatki był tytuł, który mogę łatwo dodać Texts przed moim ekspanderem tak:

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)
                    }
                }
            }
        }
    }
}

Jednak chciałbym, aby mój tytuł był "przyklejony" / "zamrożone", Czyli pozostał widoczny podczas przewijania ekranu. Mógłbym stworzyć swój nagłówek poza перелистываемого, ale siatka nie daje mi ostatecznych rozmiarów wierszy, więc nie mogę umieścić teksty nagłówków.

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

Najlepsza odpowiedź

0

To trochę banalne, ale znalazłem rozwiązanie.

Po pierwsze, należy utworzyć "fikcyjne" nagłówki, które są Items. Możesz zrobić zestaw swoich Layout.minimalWidth aby być o szerokości tekstu nagłówka, jeśli jest to potrzebne.

Następnie w elemencie przed kliknięciem utwórz swój tytuł, upewnij się, że jest on wyrównany w pionie z siatką, i umieść elementy za pomocą x wartość nagłówka.

Wreszcie, należy ustawić ujemną pole na переключаемом, aby usunąć nadmiar wiersz dodanej manekina nagłówkami.

Ja również próbowałem użyć fillWidth: true na manekiny, a następnie ustawiając width każdego elementu nagłówka, ale wadą jest to, że zmienia szerokość kolumny tabeli.

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

W innych językach

Ta strona jest w innych językach

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