PyQt6: QTableWidget, QTreeWidget, and QlistWidget cannot use custom delegates
Phil Thompson
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
> that,
> 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
> to
> '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
> derived
> 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
> environment,
> 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. :)
>
> --James
Should be fixed in the next SIP and PyQt6 snapshots (it's a code
generation bug).
Thanks,
Phil
More information about the PyQt
mailing list