SHARE
TWEET

MultiSelectTableView

a guest Jun 24th, 2013 377 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.0
  3.  
  4.  
  5. TableView {
  6.     id: table
  7.  
  8.     property var indexes: []
  9.     property int __clicks
  10.     SystemPalette{ id: syspal }
  11.  
  12.     rowDelegate: Rectangle {
  13.         property bool selected: table.__clicks && indexes.indexOf(styleData.row) > -1
  14.         width: parent.width ; height: 18
  15.         color: selected ? syspal.highlight : syspal.base
  16.     }
  17.  
  18.     itemDelegate: Text {
  19.         property bool selected: table.__clicks && indexes.indexOf(styleData.row) > -1
  20.         anchors.fill: parent
  21.         color: selected ? syspal.highlightedText : syspal.text
  22.         anchors.leftMargin: 6
  23.         verticalAlignment: Text.AlignVCenter
  24.         renderType: Text.NativeRendering
  25.         elide: styleData.elideMode
  26.         text: styleData.value
  27.     }
  28.  
  29.     onClicked: {
  30.         var indexAt = indexes.indexOf(row)
  31.         if (indexAt > -1)
  32.             indexes.splice(indexAt, 1)
  33.         else
  34.             indexes.push(row)
  35.         __clicks++  // force a re-evaluation of indexes in the delegates
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top