Created
July 12, 2020 05:20
-
-
Save chilarai/9fe1c03b4a0c9e626b277b9603102253 to your computer and use it in GitHub Desktop.
Main.qml for Qt - QSqlQueryModel - TableView
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.15 | |
import QtQuick.Window 2.15 | |
import QtQuick.Controls 2.4 | |
Window { | |
visible: true | |
width: 640 | |
height: 480 | |
title: qsTr("QSqlQueryModel - TableView") | |
// Uncomment this, if you want to call query from qml | |
// If you uncomment this, remember to comment out the followin line in main.cpp | |
// mysqlModel.callSql("SELECT * FROM users"); | |
// Component.onCompleted: { | |
// MysqlModel.callSql("SELECT * FROM users") | |
// } | |
TableView { | |
id: tableView | |
columnWidthProvider: function (column) { return 100; } | |
rowHeightProvider: function (column) { return 60; } | |
anchors.fill: parent | |
ScrollBar.horizontal: ScrollBar{} | |
ScrollBar.vertical: ScrollBar{} | |
clip: true | |
model: MysqlModel | |
// Table Body | |
delegate: Rectangle { | |
Text { | |
text: display // This is set in mysqlmodel.cpp roleNames() | |
anchors.fill: parent | |
anchors.margins: 10 | |
color: 'black' | |
font.pixelSize: 15 | |
verticalAlignment: Text.AlignVCenter | |
} | |
} | |
// Table Header | |
Row { | |
id: columnsHeader | |
y: tableView.contentY | |
z: 2 | |
Repeater { | |
model: tableView.columns > 0 ? tableView.columns : 1 | |
Label { | |
width: tableView.columnWidthProvider(modelData) | |
height: 35 | |
text: MysqlModel.headerData(modelData, Qt.Horizontal) | |
font.pixelSize: 15 | |
padding: 10 | |
verticalAlignment: Text.AlignVCenter | |
background: Rectangle { color: "#ccc" } | |
} | |
} | |
} | |
ScrollIndicator.horizontal: ScrollIndicator { } | |
ScrollIndicator.vertical: ScrollIndicator { } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment