Skip to content

Instantly share code, notes, and snippets.

@HamedMasafi
Created December 27, 2020 15:13
Show Gist options
  • Save HamedMasafi/437b42c178cbde60a4d9affe396173af to your computer and use it in GitHub Desktop.
Save HamedMasafi/437b42c178cbde60a4d9affe396173af to your computer and use it in GitHub Desktop.
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 {}
}
}
@HamedMasafi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment