[PyQt] Drag and Drop when using designer

Jan Ekholm jan.ekholm at smultron.net
Thu Oct 25 12:18:05 BST 2007


On Thursday 25 October 2007, Andreas Pakulat wrote:

> Would you elaborate a bit on that? I mean what exactly is the problem
> with the tree models? And exactly which tree models are you talking
> about? There are none in Qt itself, except for the QStandardItemModel
> which allows to build tree's, but of course is not that suitable if you
> have legacy code  that you want to wrap in Qt.

I mean building a tree model using QAbstractItemModel for a QTreeView. It is 
one of the tasks in Qt that is not for the faint of heart. The need to 
manually fiddle with index() and parent() is a mess. I've never understood 
why the model requires you to provide a "two way" access system to the data, 
ie why do you have to be able to tell both the cildren of a given node *and* 
its parent? The first is obvious, the latter is something I think Qt should 
take care of internally. As it is now most apps likely read in data to some 
custom data structures, say, lists of lists or similar. You are then more or 
less required to duplicate this own tree into another structure so that you 
can add in the stuff Qt needs. See the standard Qt "Simple Tree" example for 
an example of the extra datastructure that is required.

What is IMHO missing there is a QAbstractTreeModel that removes most of the 
gore (such as parent()) and leaves only the relevant pieces for the 
applications developer to worry about.

But this is way off-topic for this list and I apologize for that.

-- 
Jan Ekholm
jan.ekholm at smultron.net


More information about the PyQt mailing list