PyQt6: QTableWidget, QTreeWidget, and QlistWidget cannot use custom delegates
phil at riverbankcomputing.com
Fri Jan 7 17:38:12 GMT 2022
On 05/01/2022 19:21, James Evans wrote:
> QTableWidget, QTreeWidget, and QListWidget use custom ItemModel classes
> when coupled with a custom delegate, cannot be properly modified.
> When QTreeWidget calls the delegate for a specific item, it passes a
> 'QAbstractItemModel*' pointer to the delegate 'setModelData' method.
> Inside the
> 'setModelData' method, the model data is typically updated with a call
> 'model.setData( . )' which will eventually trigger an 'itemChanged'
> signal to be
> emitted by the QTreeWidget.
> The problem arises because the ItemModel classes used by these widgets
> are not
> part of the public Qt API. If the QTreeWidget model QTreeModel was
> part of the
> public API, then sip would have actually passed in a pointer to the
> QTreeModel class, and everything would work fine. Instead calling
> 'model.setData' results in a C++ call like so:
> "::QAbstractItemModel::setData( .
> )", which will always fail (as designed).
> The funny thing is, that this actually used to work (for many years)
> before I
> recently updated the version of the tools I am using.
> Qt/PyQt: 5.15.1 --> 6.2.2
> GCC: 10.2.0 --> 11.2.0
> I have attached a script that I can run successfully in my PyQt5
> but fails under the PyQt6 environment.
> NOTE: I wrote this script to highlight the problem, not as an example
> of good
> code, so no judgement please. :)
Should be fixed in the next SIP and PyQt6 snapshots (it's a code
More information about the PyQt