[Development] QtWidgets Item / Model / View: tree model examples

André Somers andre at familiesomers.nl
Tue Nov 21 17:00:43 CET 2023


Hi,

On 21-11-2023 16:31, Laszlo Papp wrote:
> Hi,
>
> The tree model examples seem to invent a custom tree item.
>
> Simple: 
> https://doc.qt.io/qt-6/qtwidgets-itemviews-simpletreemodel-example.html
> Edit: 
> https://doc.qt.io/qt-6/qtwidgets-itemviews-editabletreemodel-example.html
>
> at
>
> https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/simpletreemodel/treeitem.h?h=6.6
>
> and
>
> https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/editabletreemodel/treeitem.h?h=6.6
>
> ---
>
> Long time ago, I based my projects on these examples, inventing 
> (copying and pasting) these tree items.
>
> I wonder whether these examples could instead propagate the use of:
>
> 1. QTreeWidgetItem?
> 2. QStandardItem?
>
> It seems that e.g. the QTreeWidgetItem is nearly the same as the Tree 
> Item invented in those examples. So, why reinvent?
>
> Do you think that the tree item still has a good use case to exist in 
> those examples?
>
> If yes, what is it?
>
> If not, could we start propagating QTreeWidgetItem or QStandardItem in 
> those examples instead to avoid reinventing?

No, please. I would suggest to instead deprecate these classes, at 
minimum the Widgets (QListWidget, QTableWidget and QTreeWidget) and 
their *Item classes. These classes lead to horrible code in practice. 
Propagating their use in examples is going backwards.

QStandardItemModel is a complete misnomer, it is anything but standard. 
Instead, it should be understood as something like QPrototypeItemModel 
or something: suitable to use to play around with or whip up a quick 
test or something, but not for production code. The standard way of 
working should be writing a real model based around your own application 
specific data structures.

Cheers,

André


>
> Thank you in advance.
>
> Kind regards,
> László
>


More information about the Development mailing list