[PyQt] Drag and Drop when using designer

Andreas Pakulat apaku at gmx.de
Thu Oct 25 13:03:38 BST 2007

On 25.10.07 14:18:05, Jan Ekholm wrote:
> 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.

I don't find the creation of a tree model really problematic, I guess if
you want an answer to that question you should contact qt-interest list
or TT directly. I suspect that this is not an artificial requirement,
but actually needed for the stuff to work.

> 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.

Thats not correct. The tree model reads some input data and creates a
tree from that. The input data is discarded after the building of the
tree. You don't always need an intermediate special tree-like structure
to build a Qt model on top of some legacy data, it depends on the
structure of your legacy data.

> 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.

This doesn't work, because parent() is different in almost any tree
model. For both list and table view its easy, because parent always
returns QModelIndex(), the same with index, all it has to do is create a
model index with the given row+number, it doesn't need to care about the
given parent.


You are taking yourself far too seriously.

More information about the PyQt mailing list