I have a solution using an event filter shown below.

One would think that one would be able to intercept an event of type QEvent;;Drop heading for the TreeViews but I was unable to detect one. Strange...Unless it is the MetaCall event it receives just after the drop. Since I could not make use of the information in the meta call event I can't know if it was the Drop event or not.

At anyrate, the QEvent::ChildRemoved event type proved to work just as well. Perhaps even better since I should only get that when the model/view accepts the drop and I don't have to put in lots of ugly code to send the event and check its return to see if the drop was accepted or not.

Enjoy...

-Mic

Qt Code:
  1. #include <QtGui>
  2.  
  3. class MainWindow : public QMainWindow
  4. {
  5. Q_OBJECT
  6.  
  7. public:
  8. MainWindow( QWidget *parent = 0 ) : QMainWindow( parent)
  9. {
  10. splitter = new QSplitter( this );
  11.  
  12. model = new QDirModel( this );
  13. model->setReadOnly( false );
  14.  
  15. tree = new QTreeView;
  16. tree->setModel( model );
  17. tree->setRootIndex( model->index( QString( "/home/randy" ) ) );
  18.  
  19. model1 = new QDirModel( this );
  20. model1->setReadOnly( false );
  21.  
  22. righttree = new QTreeView;
  23. righttree->setModel( model1 );
  24. righttree->setRootIndex( model1->index( QString( "/tmp" ) ) );
  25.  
  26. tree->setDragEnabled( true );
  27. tree->setAcceptDrops( true );
  28. tree->setDropIndicatorShown( true );
  29. tree->setDragDropOverwriteMode( false );
  30. tree->installEventFilter( this );
  31.  
  32. righttree->setDragEnabled( true );
  33. righttree->setAcceptDrops( true );
  34. righttree->setDropIndicatorShown( true );
  35. righttree->setDragDropOverwriteMode( false );
  36. righttree->installEventFilter( this );
  37.  
  38. splitter->addWidget( tree );
  39. splitter->addWidget( righttree );
  40.  
  41. setCentralWidget( splitter );
  42. }
  43.  
  44. bool eventFilter( QObject *target, QEvent *event )
  45. {
  46. if( target == tree && event->type() == QEvent::ChildRemoved ) {
  47. model->refresh( tree->rootIndex() );
  48. }
  49. else if( target == righttree && event->type() == QEvent::ChildRemoved ) {
  50. model1->refresh( righttree->rootIndex() );
  51. }
  52. return false;
  53. }
  54.  
  55. private:
  56. QSplitter *splitter;
  57. QDirModel *model;
  58. QTreeView *tree;
  59. QDirModel *model1;
  60. QTreeView *righttree;
  61. QTimer *timer;
  62. };
  63.  
  64. int main( int argc, char *argv[] )
  65. {
  66. // a "file manager" at simplest :)
  67. QApplication a( argc, argv );
  68. MainWindow window;
  69. window.show();
  70. return a.exec( );
  71. }
  72.  
  73. #include "app.moc"
To copy to clipboard, switch view to plain text mode