<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[how to update only one row of model in qtableview @ pyside6]]></title><description><![CDATA[<p dir="auto">I want to update only 1 row or 1 cell.</p>
<p dir="auto">but all cell is updated when datachanged is emitted.</p>
<p dir="auto">data() was called hundreds times for each cells and each roles.</p>
<p dir="auto">what is wrong with this code ?</p>
<p dir="auto">class TestitemTableModel(QAbstractTableModel):</p>
<pre><code>def __init__(self, data):
    super(TestitemTableModel, self).__init__()
    self._data = data

def data(self, index, role):

    if role == QtCore.Qt.DisplayRole:
        value = self._data.iloc[index.row(), index.column()]
        return str(value)

    if role == QtCore.Qt.TextAlignmentRole:
        return int(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter)


def setData(self, index, value, role):

    if not index.isValid():
        return False

    if role == QtCore.Qt.DisplayRole:
        self._data.iloc[index.row(), index.column()] = 'WTF'
        
        self.dataChanged.emit(index, index)

        return True

    return QAbstractTableModel.setData(self,index,value,role)

def rowCount(self, index):
    return self._data.shape[0]

def columnCount(self, index):
    return self._data.shape[1]

def headerData(self, section, orientation, role):
    if role == QtCore.Qt.DisplayRole:
        if orientation == QtCore.Qt.Horizontal:
            return str(self._data.columns[section])
        
        if orientation == QtCore.Qt.Vertical:
            return str(self._data.index[section])
</code></pre>
]]></description><link>https://forum.qt.io/topic/142430/how-to-update-only-one-row-of-model-in-qtableview-pyside6</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 05:54:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142430.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Jan 2023 08:07:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to update only one row of model in qtableview @ pyside6 on Thu, 26 Jan 2023 01:50:44 GMT]]></title><description><![CDATA[<p dir="auto">This situation is occured by below option.</p>
<p dir="auto">tableview.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)</p>
<p dir="auto">Works fine when I disable that option.</p>
]]></description><link>https://forum.qt.io/post/745232</link><guid isPermaLink="true">https://forum.qt.io/post/745232</guid><dc:creator><![CDATA[Aiden.k]]></dc:creator><pubDate>Thu, 26 Jan 2023 01:50:44 GMT</pubDate></item><item><title><![CDATA[Reply to how to update only one row of model in qtableview @ pyside6 on Wed, 25 Jan 2023 09:35:28 GMT]]></title><description><![CDATA[<p dir="auto">@Aiden-k<br />
I don't know exactly what your problem is, or what you are trying to do.</p>
<p dir="auto">Qt infrastructure will call <code>data()</code> multiple times with different roles.</p>
<p dir="auto">Your <code>setData()</code> sets the data on the <code>DisplayRole</code>.  This is wrong.  <code>setData()</code> is called with <code>EditRole</code> to make an update on the value.  Start by getting that right.</p>
]]></description><link>https://forum.qt.io/post/745136</link><guid isPermaLink="true">https://forum.qt.io/post/745136</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 25 Jan 2023 09:35:28 GMT</pubDate></item></channel></rss>