Created
December 27, 2020 15:13
-
-
Save HamedMasafi/437b42c178cbde60a4d9affe396173af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
import QtQuick.Layouts 1.12 | |
import QtQuick.Controls 2.12 | |
import QtQml.Models 2.12 | |
Item { | |
id: root | |
property alias model: tableView.model | |
default property list<TableColumn> columns | |
component TableColumn : QtObject { | |
property string title | |
property string role | |
property bool fillWidth: false | |
property int size: -1 | |
} | |
component TableRow : ItemDelegate { | |
height: 40 | |
width: parent.width | |
property bool isHeader: false | |
RowLayout { | |
property var _d: model | |
anchors.fill: parent | |
anchors.leftMargin: 9 | |
Repeater { | |
model: root.columns | |
Label { | |
text: parent.parent.isHeader ? modelData.title : parent._d[modelData.role] | |
Layout.fillWidth: modelData.fillWidth | |
Layout.preferredWidth: modelData.size !== '*' | |
? modelData.size : 20 | |
} | |
} | |
} | |
} | |
TableRow { | |
id: header | |
anchors.left: parent.left | |
anchors.right: parent.right | |
anchors.top: parent.top | |
background: null | |
isHeader: true | |
height: 60 | |
} | |
ListView { | |
id: tableView | |
clip: true | |
anchors.fill: parent | |
anchors.topMargin: header.height | |
delegate: TableRow {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you write a simple example of this file ? ... Thanks <3