QTreeWidget & Drag Events

140 views
Skip to first unread message

Karl

unread,
Oct 7, 2012, 8:37:35 AM10/7/12
to qtcon...@googlegroups.com
Dear All,

the default drag & drop behaviour of a QTreeWidget works fine.  But I did not manage to delegate the drag events to implement more specific features.

M->oTree:setDragEnabled( .t. )

M->oTree:connect( QEvent_DragEnter, {|p| execEvent( _dragEnterEvent__, p ) } )
M->oTree:connect( QEvent_DragMove , {|p| execEvent( _dragMoveEvent__ , p ) } )
M->oTree:connect( QEvent_Drop     , {|p| execEvent( _dropEvent__     , p ) } )


In my case the function execEvent() is never called?!

Please find a simple self contained example attached. It does work with other QWidgets e.g. QLineEdit or alike.  I also tried to connect to the model and/or to each QTreeWidgetItem.  No effect.  Yes I looked in hbIDE (e.g. in docks.prg) but I can't find the difference or what I am missing.

Thank you very much
 Karl
test.prg

Pritpal Bedi

unread,
Oct 7, 2012, 10:45:31 AM10/7/12
to qtcon...@googlegroups.com
Hello Karl


the default drag & drop behaviour of a QTreeWidget works fine.  But I did not manage to delegate the drag events to implement more specific features.

M->oTree:setDragEnabled( .t. )

M->oTree:connect( QEvent_DragEnter, {|p| execEvent( _dragEnterEvent__, p ) } )
M->oTree:connect( QEvent_DragMove , {|p| execEvent( _dragMoveEvent__ , p ) } )
M->oTree:connect( QEvent_Drop     , {|p| execEvent( _dropEvent__     , p ) } )


In my case the function execEvent() is never called?!

Please look at hbide/projectwizard.prg.
This implements drag/drop of QTreeWidget to an extended level. 
QTreeWidget is implements drag/drop in different way than other widgets.

And let us know if you succeeded and in what way you implement 
in our application.

Pritpal Bedi
a student of software analysis & concepts

Karl

unread,
Oct 7, 2012, 12:28:45 PM10/7/12
to qtcon...@googlegroups.com
Dear Pritpal,

I also looked into projectWizard.prg.  What I don't understand is you enable the drag&drop in the QTreeWidget (:treeSrc):

      ::oUI:treeSrc:setDragEnabled( .t. )
      ::oUI:treeSrc:setDropIndicatorShown( .t. )
      ::oUI:treeSrc:setAcceptDrops( .t. )

Then you connect to the drag events in the parent QFrame (:frameSrc):

      ::oUI:frameSrc:setAcceptDrops( .t. )
      ::oUI:frameSrc:connect( QEvent_DragEnter, {|p| ::execEvent( __frameSrc_dragEnterEvent__, p ) } )
      ::oUI:frameSrc:connect( QEvent_DragMove , {|p| ::execEvent( __frameSrc_dragMoveEvent__ , p ) } )
      ::oUI:frameSrc:connect( QEvent_Drop     , {|p| ::execEvent( __frameSrc_dropEvent__     , p ) } )

This does not seem logical to me. But even if I try to use the same setup (adding a parent frame to my oTree) I do not get any events?!
 
And let us know if you succeeded and in what way you implement 
in our application.

Currently I am writing a tool to administrate my TODO items for internal use only.  Like this I learn hbqt which I plan on using to replace step by step the old GUI (gtwvt) of a harbour application of one of my customers.

Best regards
  Karl
 

Pritpal Bedi

unread,
Oct 7, 2012, 3:05:20 PM10/7/12
to qtcon...@googlegroups.com
Hi Karl


I also looked into projectWizard.prg.  What I don't understand is you enable the drag&drop in the QTreeWidget (:treeSrc):

      ::oUI:treeSrc:setDragEnabled( .t. )
      ::oUI:treeSrc:setDropIndicatorShown( .t. )
      ::oUI:treeSrc:setAcceptDrops( .t. )


Because QTreeWidget implements drag/drop in different wan than other QWidget(s).
Please read Qt documentation. The above code enables to accept drops and also enables
drag/drop from inside of QTreeWidgetItems. 
 
Then you connect to the drag events in the parent QFrame (:frameSrc):

      ::oUI:frameSrc:setAcceptDrops( .t. )
      ::oUI:frameSrc:connect( QEvent_DragEnter, {|p| ::execEvent( __frameSrc_dragEnterEvent__, p ) } )
      ::oUI:frameSrc:connect( QEvent_DragMove , {|p| ::execEvent( __frameSrc_dragMoveEvent__ , p ) } )
      ::oUI:frameSrc:connect( QEvent_Drop     , {|p| ::execEvent( __frameSrc_dropEvent__     , p ) } )

This does not seem logical to me. But even if I try to use the same setup (adding a parent frame to my oTree) I do not get any events?


Logical or Illogical depend upon the usage. This is perfectly logical in this context.
As told earlier, QTreeWidget does not accept drops from outside of QTreeWidget controls.
So I enabled the parent to accept the drops, which in turn populate the QTreeWidget.
For example, in above code, whenever user drags sources from explorer to this 
QTreeWidget, which are accpted by its parent frame, are parsed and populated to 
respective nodes, i.e., .prg under node "Prg Files", and so on.

Try to have a feel of it by playing with <Projects><New Project Wizard> opened dialog.
Do not open existing .hbp as this implementation is still work-in-progress.

Thanks for sharing your usage details.

Pritpal Bedi

PS: the drop events will be captured in the parent handellers. Parent has to be 
enabled for accepting the drops.
Reply all
Reply to author
Forward
0 new messages