Hi, I&#39;m trying to write an alternative to qdataFrameModel that has the same speed, but has a more standard treatment of roles. I have the following. Two questions though:<br><br>1) The items get drawn with a checkbox next to them. I make sure the flags() method avoids Qt$Qt$ItemIsUserCheckable, but it is still there. Any idea what I&#39;m doing wrong/missing?<br>
<br>2) In the data() method, the Qt docs say I should return an invalid QVariant instead of 0. I return NA. Is that right? I also wonder why I can&#39;t just call super to get the default data for the role from the parent.<br>
<br>Thanks for any help, --John<br><br><br>library(qtbase)<br><br>n &lt;- 10 ## or even 1e6<br>Df &lt;- data.frame(a=1:n, b= rnorm(n))<br><br>qsetClass(&quot;DfModel&quot;, Qt$QAbstractTableModel, function(parent=NULL) {<br>
  super(parent)<br>  this$dataframename &lt;- &quot;Df&quot;  ## generalize after testing<br>})<br><br>qsetMethod(&quot;Df&quot;, DfModel, function() {<br>  get(this$dataframename, envir=.GlobalEnv)<br>})<br><br>qsetMethod(&quot;rowCount&quot;, DfModel, function(index) nrow(this$Df()))<br>
qsetMethod(&quot;columnCount&quot;, DfModel, function(index) ncol(this$Df()))<br><br>qsetMethod(&quot;data&quot;, DfModel, function(index, role) {<br>  d &lt;- this$Df()<br>  if(index$isValid()) {<br>    if(role == Qt$Qt$DisplayRole)<br>
      out &lt;- as.character(d[index$row() + 1, index$column() + 1])<br>    else if(role == Qt$Qt$EditRole)<br>      out &lt;- as.character(d[index$row() + 1, index$column() + 1])<br>    else <br>      out &lt;- NA<br>    ##    super(&quot;data&quot;, index, role) ## why does this fail?<br>
  }<br>  return(out)<br>})<br><br>## coerce value to fit into x<br>fitIn &lt;- function(x, value) UseMethod(&quot;fitIn&quot;)<br>fitIn.default &lt;- function(x, value) value<br>fitIn.numeric &lt;- function(x, value) as.numeric(value)<br>
fitIn.integer &lt;- function(x, value) as.integer(value)<br><br>qsetMethod(&quot;setData&quot;, DfModel, function(index, value, role) {<br><br>  if(index$isValid() &amp;&amp; role == Qt$Qt$EditRole) {<br>    d &lt;- this$Df()<br>
    x &lt;- d[, index$column() + 1]<br>    d[index$row() + 1, index$column() + 1] &lt;- fitIn(x,value)<br><br>    assign(this$dataframename, d, envir=.GlobalEnv)<br>    <br>    dataChanged(index, index)<br>    return(TRUE)<br>
  } else {<br>    return(FALSE)<br>  }<br>})<br><br>qsetMethod(&quot;flags&quot;, DfModel, function(index) {<br>  if(!index$isValid()) {<br>    return(Qt$Qt$ItemIsEnabled)<br>  } else {<br>    curFlags &lt;- super(&quot;flags&quot;, index)<br>
    if(curFlags &amp; Qt$Qt$ItemIsUserCheckable)<br>      curFlags &lt;- curFlags - Qt$Qt$ItemIsUserCheckable # try to remove checkable<br>    return(curFlags | Qt$Qt$ItemIsEditable)<br>  }<br>})<br><br>## test it<br>model &lt;- DfModel()<br>
<br>view &lt;- Qt$QTableView()<br>view$setModel(model)<br><br>view$setEditTriggers(Qt$QAbstractItemView$AllEditTriggers)<br><br>view$show()<br>view$raise()<br><br clear="all"><br>