From aab4802d7e92af04589ecdbecfe265fbbbefb22e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Thu, 15 Jun 2023 07:39:45 +0800 Subject: [PATCH] update --- .../FluentUI/Controls/FluTableView2.qml | 116 ++++++++++-------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/src/imports/FluentUI/Controls/FluTableView2.qml b/src/imports/FluentUI/Controls/FluTableView2.qml index fe2a5e3c..9ea539d6 100644 --- a/src/imports/FluentUI/Controls/FluTableView2.qml +++ b/src/imports/FluentUI/Controls/FluTableView2.qml @@ -5,35 +5,16 @@ import QtQuick.Layouts import Qt.labs.qmlmodels import FluentUI -TableView { + +Rectangle { + + id:control + + + property var columnSource property var dataSource - id:control - ListModel{ - id:model_columns - } - columnWidthProvider: function (column) { - return columnSource[column].width - } - rowHeightProvider: function (column) { - return 60 - } - topMargin: columnsHeader.implicitHeight - model: table_model - ScrollBar.horizontal: FluScrollBar{} - ScrollBar.vertical: FluScrollBar{} - clip: true - boundsBehavior:Flickable.StopAtBounds - delegate: Rectangle { - color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1) - FluText { - text: display - anchors.fill: parent - anchors.margins: 10 - verticalAlignment: Text.AlignVCenter - } - } - + color: Qt.styleHints.appearance === Qt.Light ? palette.mid : palette.midlight onColumnSourceChanged: { if(columnSource.length!==0){ var com_column = Qt.createComponent("FluTableModelColumn.qml") @@ -48,6 +29,10 @@ TableView { } } + TableModel { + id:table_model + } + onDataSourceChanged: { table_model.clear() dataSource.forEach(function(item){ @@ -55,30 +40,63 @@ TableView { }) } - TableModel { - id:table_model - } + TableView { + id:table_view + anchors.left: header_vertical.right + anchors.top: header_horizontal.bottom + anchors.right: parent.right + anchors.bottom: parent.bottom + ListModel{ + id:model_columns + } + columnWidthProvider: function(column) { + let w = explicitColumnWidth(column) + if (w >= 100) + return Math.max(100, w);; + return implicitColumnWidth(column) + } + rowHeightProvider: function(row) { + let h = explicitRowHeight(row) + if (h >= 0) + return Math.max(60, h); + return implicitRowHeight(row) + } - Row { - id: columnsHeader - y: control.contentY - z: 2 - Repeater { - model: columnSource - Rectangle{ - height: 35 - width: control.columnWidthProvider(index) - color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1) - FluText { - text: modelData.title - font: FluTextStyle.BodyStrong - anchors{ - verticalCenter: parent.verticalCenter - left: parent.left - leftMargin: 10 - } - } + model: table_model + ScrollBar.horizontal: FluScrollBar{} + ScrollBar.vertical: FluScrollBar{} + clip: true + delegate: Rectangle { + implicitHeight: 60 + implicitWidth: columnSource[column].width + color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1) + FluText { + text: display + anchors.fill: parent + anchors.margins: 10 + verticalAlignment: Text.AlignVCenter } } } + + + HorizontalHeaderView { + id: header_horizontal + anchors.left: table_view.left + anchors.top: parent.top + syncView: table_view + clip: true + } + + VerticalHeaderView { + id: header_vertical + anchors.top: table_view.top + anchors.left: parent.left + syncView: table_view + clip: true + } + + + } +