title: QAbstractTableModel updating background color
body: <p>I have a table with 3 columns: {"Scanned","Qty", "Item"}. I am trying to highlight the particular row if the "Scanned" and "Qty" column value matches. I saw some posts which says to implement it in the following</p>
  
  <blockquote>
    <p>data(const QModelIndex &amp;index, int role) const</p>
  </blockquote>
  
  <p>I have tried as follow to just change the background color of the table rows regardless but it does not seem to work as suggested:</p>
  
  <pre><code>QVariant TransitItemTableModel::data(const QModelIndex &amp;index, int role) const
  {
      switch (role) {
      case TableDataRow:
      {
          return table.at(index.row()).at(index.column());
      }
      case HeadingRow:
      {
          if (index.row() == 0) {
              return true;
          } else {
              return false;
          }
      }
      case Qt::BackgroundRole:
      {
          QBrush redBackground(Qt::green);
          return redBackground;
  
      }
      default:
          break;
      }
  
      return QVariant();
  }
  </code></pre>
  
  <p>I am calling </p>
  
  <blockquote>
    <p>emit dataChanged
    in the following code below:</p>
  </blockquote>
  
  <pre><code>bool TransitItemTableModel::setData(const QModelIndex &amp;index, const QVariant &amp;value,
                                 int role)  {
      if (!index.isValid() || 
              index.row() &lt; 0 || index.row() &gt;= table.size())
          return false;
  
      QList&lt;QString&gt; list1 = value.value&lt;QList&lt;QString&gt;&gt;();
      QVector&lt;QString&gt; list2 = list1.toVector();
  
      table.replace(index.row(), list2);
      emit dataChanged(index, index, {TableDataRow});
      return true;
  }
  </code></pre>
  
  <p>Just for additional info, I have the following roles defined:</p>
  
  <pre><code>enum TableRoles {
          TableDataRow = Qt::UserRole + 1,
          HeadingRow
      };
  </code></pre>
  
  <p>With regards to the QML code, I am using the following code for display as Table.qml and the lower portion of code shows part of the code using this Table.qml:</p>
  
  <pre><code>import QtQuick 2.12
  import QtQuick.Controls 2.12
  import QtQuick.Layouts 1.12
  
  TableView {
      id: root
      anchors.fill: parent
      clip: true
      signal clicked(int row, int column)
      property var columnWidths: [0.5, 0.5]   // as fractions of parent width
                                              // preferably overwrite this when using
      columnWidthProvider: function (column) { return Math.max(parent.width * columnWidths[column], 1) }
  
      delegate: Rectangle {
          implicitHeight: text.implicitHeight
          border.color: "#dddddd"
          color: (heading==true)?"#dddddd":"white"
          Text {
              id: text
              text: tabledata
              width: parent.width
              wrapMode: Text.Wrap
              padding: 5
          }
          MouseArea{
              anchors.fill: parent
              onClicked: root.clicked(model.row, model.column)
          }
      }
  }
  </code></pre>
  
  <pre><code>Rectangle {
        color: "transparent"
        Layout.fillWidth: true
        Layout.preferredHeight: parent.height - 250
  
        Components.Table {
            model: _transitItemTableModelAPI
            columnWidths: [0.2, 0.15, 0.65]
        }
      }
  </code></pre>