Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TreeView{
- id:tree
- x: 0
- //anchors.fill: parent
- width: 335
- height: 420
- anchors.topMargin: 0
- anchors.bottomMargin: 6
- anchors.rightMargin: 1287
- anchors.bottom: frame.top
- anchors.top: parent.top
- clip: true
- model: qjsonmodel
- TableViewColumn{
- title:"Defects"
- }
- }
- ...
- class QJsonModel : public QAbstractItemModel
- {
- Q_OBJECT
- public:
- explicit QJsonModel(QObject *parent = 0);
- ~QJsonModel();
- enum JsonRoles{
- KeyRole = Qt::UserRole + 1000,
- ValueRole
- };
- ...
- QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
- ...
- };
- ...
- QVariant QJsonModel::data(const QModelIndex &index, int role) const
- {
- if (!index.isValid())
- return QVariant();
- QJsonTreeItem *item = static_cast<QJsonTreeItem*>(index.internalPointer());
- if (role == Qt::DisplayRole) {
- if (index.column() == 0)
- return QString("%1").arg(item->key());
- if (index.column() == 1)
- return QString("%1").arg(item->value());
- }
- else if (role == KeyRole) {
- return QString("%1").arg(item->key());
- }
- else if(role == ValueRole){
- return QString("%1").arg(item->value());
- }
- return QVariant();
- }
- ...
- QHash<int, QByteArray> QJsonModel::roleNames() const
- {
- QHash<int, QByteArray> roles;
- roles[KeyRole] = "keyData";
- roles[ValueRole] = "valueData";
- return roles;
- }
- ...
- import QtQuick 2.9
- import QtQuick.Window 2.2
- import QtQuick.Controls 1.4
- Window {
- visible: true
- width: 640
- height: 480
- title: qsTr("Hello World")
- TreeView{
- anchors.fill: parent
- model: qjsonmodel
- TableViewColumn{
- title:"Key"
- role: "keyData"
- }
- TableViewColumn{
- title:"Role"
- role: "valueData"
- }
- }
- }
Add Comment
Please, Sign In to add comment