PyQt6: QTableWidget, QTreeWidget, and QlistWidget cannot use custom delegates

Maurizio Berti maurizio.berti at gmail.com
Thu Jan 6 19:36:22 GMT 2022


I can confirm the same with PyQt 6.2.2 and Python 3.9.5.
The problem is obviously not the delegate, but setModel() itself, which
returns True on PyQt5 but False on PyQt6.

Maurizio

Il giorno gio 6 gen 2022 alle ore 18:06 Phil Thompson <
phil at riverbankcomputing.com> ha scritto:

> 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
>
> Define "fails". I get the same output for PyQt5 and PyQt6.
>
> Phil
>


-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220106/3e15d930/attachment.htm>


More information about the PyQt mailing list