Advertisement
Guest User

TableView QML

a guest
Aug 20th, 2013
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ApplicationWindow {
  2.     id: appWindow
  3.     title: qsTr("Permissions")
  4.     width: 640
  5.     height: 480
  6.  
  7.     ListModel {
  8.         id: permissionsModel
  9.  
  10.         ListElement { name: "Table 1"; read: true; add: true; edit: false }
  11.         ListElement { name: "Users";   read: true; add: true; remove: true; edit: true }
  12.     }
  13.  
  14.     Component {
  15.         id: checkBoxDelegate
  16.  
  17.         Item {
  18.             CheckBox {
  19.                 anchors.fill: parent
  20.                 checked: styleData.value
  21.             }
  22.         }
  23.     }
  24.  
  25.     Component {
  26.         id: verticalHeaderDelegate
  27.  
  28.         Item {
  29.             Loader {
  30.                 property QtObject styleData: QtObject {
  31.                     property string value: styleData.value
  32.                     property bool pressed
  33.                     property bool containsMouse
  34.                     property int column
  35.                 }
  36.  
  37.                 anchors.fill: parent
  38.                 sourceComponent: table.headerDelegate
  39.             }
  40.         }
  41.     }
  42.  
  43.     Component {
  44.         id: rowDelegate
  45.  
  46.         Item {
  47.             Loader {
  48.                 anchors.fill: parent
  49.                 //sourceComponent: table.rowDelegate  // "The program has unexpectedly finished."
  50.             }
  51.  
  52.             Component.onCompleted: height = 1.2*height  // Bad
  53.         }
  54.     }
  55.  
  56.     TableView {
  57.         id: table
  58.  
  59.         property int columnWidth: width/columnCount - 1  // Bad
  60.  
  61.         anchors.fill: parent
  62.         model: permissionsModel
  63.         rowDelegate: rowDelegate
  64.  
  65.         TableViewColumn { title: "Permission"; delegate: verticalHeaderDelegate; role: "name";   width: table.columnWidth }
  66.         TableViewColumn { title: "Read";       delegate: checkBoxDelegate;       role: "read";   width: table.columnWidth }
  67.         TableViewColumn { title: "Add";        delegate: checkBoxDelegate;       role: "add";    width: table.columnWidth }
  68.         TableViewColumn { title: "Remove";     delegate: checkBoxDelegate;       role: "remove"; width: table.columnWidth }
  69.         TableViewColumn { title: "Modify";     delegate: checkBoxDelegate;       role: "edit";   width: table.columnWidth }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement