<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6001.18148" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I'm porting a Tkinter application to PyQt.&nbsp; 
This is my first time using PyQt so I realize I may be doing this all 
wrong.&nbsp; My application includes a QTreeView backed by my own model.&nbsp; 
The view provides the user a means to hierarchically create, edit and organize 
large amounts of information.&nbsp; Ordering of the nodes in the tree is 
important.&nbsp; Consequently I've implemented several ways for the user to 
reorganize the tree including&nbsp;drag and drop reordering.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I've&nbsp;tried using QTreeView's built-in drag and 
drop.&nbsp; It works OK, but I really need more than it can provide.&nbsp; The 
built-in drag and drop always drops content &lt;i&gt;before&lt;/i&gt; the entry 
under the mouse cursor.&nbsp; However, I want to be able to drop content 
&lt;i&gt;before&lt;/i&gt;, &lt;i&gt;after&lt;/i&gt; or &lt;i&gt;as a child 
of&lt;/i&gt; the entry under the mouse cursor.&nbsp; The location (before, after 
or as a child of) is determined by the location of the drag cursor's hot spot 
relative to the rectangle over which it is currently hovering.&nbsp; E.g. if the 
hot spot is hovering over the &lt;i&gt;top half&lt;/i&gt; of an entry, the drop 
would occur &lt;i&gt;before&lt;/i&gt; that entry, while if it's in the 
&lt;i&gt;bottom half&lt;/i&gt; the drop would occur &lt;i&gt;after&lt;/i&gt; the 
entry.&nbsp; However, if it's in the &lt;i&gt;bottom half&lt;/I&gt; 
&lt;B&gt;and&lt;/b&gt; more than 20 pixels to the right of the left edge of the 
entry, it will be dropped as a child.&nbsp; To provide feedback to the user as 
to where the drop will occur I wish to change the mouse cursor as the drag 
operation is taking place.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>To implement all of this I've subclassed QTreeView 
and overridden mousePressEvent(), mouseMoveEvent(), dragMoveEvent(), 
dragEnterEvent(), dragLeaveEvent() and dropEvent() (as per the drag and drop 
documentation in TrollTech's Qt distribution).&nbsp; In my constructor I have 
the following code:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.insertBefore_cursor&nbsp; = 
RES.getDragCursor('OutlineView','DnD_insertBeforeCursor')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.insertAfter_cursor&nbsp;&nbsp; = 
RES.getDragCursor('OutlineView','DnD_insertAfterCursor')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.insertChild_cursor&nbsp;&nbsp; = 
RES.getDragCursor('OutlineView','DnD_insertChildCursor')</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>RES is a subclass object of python's 
SafeConfigParser which reads ini files.&nbsp; My getDragCursor() reads in the 
following lines</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>[OutlineView]<BR>DnD_insertBeforeCursor&nbsp; = 
resources/cursors/arrow_insertBefore.png:14:12<BR>DnD_insertAfterCursor&nbsp;&nbsp; 

resources/cursors/arrow_insertAfter.png:14:12<BR>DnD_insertChildCursor&nbsp;&nbsp; 
= resources/cursors/arrow_insertChild.png:22:12</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>getDragCursor()&nbsp;returns&nbsp;a tuple of 
two:&nbsp;&nbsp;a QPixmap and a QPoint (the hot spot).&nbsp; Next my 
dragMoveEvent()</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; def dragMoveEvent( self, event 
):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; referenceIndex,relation = 
self._dnd_insertionPos( event )</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if relation == 
'before':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixmap, hotspot = 
self.insertBefore_cursor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif relation == 
'after':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixmap, hotspot = 
self.insertAfter_cursor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elif relation == 
'child':<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixmap, hotspot = 
self.insertChild_cursor<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
else:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise 
Exception()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
self.drag.setDragCursor( pixmap, QtCore.Qt.CopyAction + QtCore.Qt.MoveAction 
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.drag.setHotSpot( hotspot )</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>_dnd_insertionPos()&nbsp;calls event.pos(), does a 
bit of math and returns a tuple consisting of the referenceIndex (a QModelIndex 
for the item over which the mouse cursur is hovering) and a relation string 
('before', 'after' or 'child').&nbsp; I use this second value to select a 
cursor.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>When I run my software and attempt a drag, all I 
see is the built-in drag cursor.&nbsp; My own cursors are never displayed.&nbsp; 
However, if I put a break point after the setDragCursor(), my cursor DOES get 
displayed.&nbsp; This leads me to suspect that I may need to make some sort of 
call after setDropCursor() to give the event loop or drawing routines some 
processor time.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Thanks for the help.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><FONT face=Arial size=2>
<DIV><BR>Sorry about all the text here.&nbsp; I wanted to be sure to provide 
enough info to allow a diagnosis.&nbsp; Also, sorry that I haven't provided any 
runnable code&nbsp;to get a clearer indication of the problem.&nbsp; There's 
quite a bit of code and I wasn't able to trim it down to a decent 
sized-example.&nbsp; My complete project is up in googlecode in a project called 
MindTree if more context is needed to help diagnose this (or if you're just 
curious).</DIV>
<DIV></FONT>&nbsp;</DIV></BODY></HTML>