This commit is contained in:
朱子楚\zhuzi 2023-06-15 07:39:45 +08:00
parent 441c1ab03c
commit aab4802d7e

View File

@ -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)
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: modelData.title
font: FluTextStyle.BodyStrong
anchors{
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 10
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
}
}