<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">I tried using multiData with this code snippet but it seems to crash when setting roleData.setData(...). Also I notice that the role values might be negative. (Btw, ic is icecream print).<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"> def _itemData(self, item, col):<br> match <a href="http://col.name">col.name</a>:<br> case 'code':<br> return {<br> Qt.DisplayRole: item.code,<br> }<br> case 'earnings_chg':<br> return {<br> Qt.DisplayRole: f'{item.earnings_chg}%',<br> }<br> case 'time':<br> return {<br> Qt.DisplayRole: item.time.strftime('%Y-%m-%d'),<br> }<br> case 'earnings':<br> return {<br> Qt.DisplayRole: formatMoney(item.earnings),<br> }<br><br> def multiData(self, index, roleDataSpan):<br> ic(index, roleDataSpan)<br> item = self._items[index.row()]<br> col = self.COLUMNS[index.column()]<br> itemData = self._itemData(item, col)<br> for roleData in roleDataSpan:<br> role = roleData.role()<br> ic(role)<br> if value := itemData.get(role):<br> roleData.setData(value)<br> else:<br> match role:<br> case Qt.FontRole:<br> roleData.setData(style.TABLE_FONT)<br> case Qt.TextAlignmentRole:<br> align = col.align<br> if align == 'C':<br> roleData.setData(Qt.AlignCenter)<br> elif align == 'R':<br> roleData.setData(Qt.AlignVCenter | Qt.AlignRight)</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">ic| earnings.py:66 in multiData()<br> index: <PyQt6.QtCore.QModelIndex object at 0x000001D17B77D000><br> roleDataSpan: <PyQt6.QtCore.QModelRoleDataSpan object at 0x000001D17B77D4D0><br>ic| earnings.py:72 in multiData()- role: 6<br>ic| earnings.py:72 in multiData()- role: 7<br>ic| earnings.py:72 in multiData()- role: 9<br>ic| earnings.py:72 in multiData()- role: 10<br>ic| earnings.py:72 in multiData()- role: 1<br>ic| earnings.py:72 in multiData()- role: 0<br>ic| earnings.py:72 in multiData()- role: 8<br>ic| earnings.py:72 in multiData()- role: -948493808<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 2033014364<br>ic| earnings.py:72 in multiData()- role: 2<br>ic| earnings.py:72 in multiData()- role: 16777216<br>ic| earnings.py:72 in multiData()- role: 1893028080<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 2033014458<br>ic| earnings.py:72 in multiData()- role: 2<br>ic| earnings.py:72 in multiData()- role: 2033021932<br>ic| earnings.py:72 in multiData()- role: 3<br>ic| earnings.py:72 in multiData()- role: 524288<br>ic| earnings.py:72 in multiData()- role: 1893028080<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 1897532384<br>ic| earnings.py:72 in multiData()- role: 2033022038<br>ic| earnings.py:72 in multiData()- role: 1<br>ic| earnings.py:72 in multiData()- role: 22528<br>ic| earnings.py:72 in multiData()- role: 1893028080</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 27, 2023 at 10:45 PM Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 14/08/2023 16:21, Jakub Fránek wrote:<br>
> Hello<br>
> <br>
> I am working on a PyQt app that features a large QTableView driven by a<br>
> custom QAbstractTableModel implementation. Profiling shows that even <br>
> after<br>
> heavy optimization, the program spends a lot of time calling<br>
> QAbstractItemModel.data method.<br>
> <br>
> I think that QAbstractItemModel.multiData method could improve the<br>
> performance considerably, however it seems that PyQt does not support <br>
> this<br>
> binding (since it does not even support QModelRoleDataSpan).<br>
> <br>
> My question is: is there any plan of supporting<br>
> QAbstractItemModel.multiData method in the future? If there is no such <br>
> plan<br>
> yet, I would like to cast my vote and humbly request this binding in <br>
> some<br>
> future version of PyQt.<br>
<br>
multiData() and QModelRoleSpan are implemented in the next snapshot - <br>
please test.<br>
<br>
Phil<br>
</blockquote></div>