Hello Everybody,

I have written a program that permit drag and drop in a TreeView.
I have written a model like one written in internet

Qt Code:
  1. class ModelBookNodeDescModel: public QAbstractItemModel
  2. {
  3. public slots:
  4. void saveToXml();
  5. public:
  6. ModelBookNodeDescModel(std::string full_path, QObject *parent = 0);
  7. ~ModelBookNodeDescModel();
  8.  
  9. void setRootNode(ut::types::tModelBookNodeDesc *node);
  10. QModelIndex exportRootIndex();
  11. static void setParentOfAllNodes(ut::types::tModelBookNodeDesc *node);
  12.  
  13. QModelIndex createQModelIndex(ut::types::tModelBookNodeDesc &item);
  14.  
  15. QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  16. QModelIndex parent(const QModelIndex &child) const;
  17.  
  18. int rowCount(const QModelIndex &parent) const;
  19. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  20.  
  21. QVariant data(const QModelIndex &index, int role) const;
  22. Qt::ItemFlags flags(const QModelIndex &index) const;
  23. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  24.  
  25. bool insertRows(int position, int rows, std::vector<ut::types::tModelBookNodeDesc*> &tab ,const QModelIndex &parent = QModelIndex());
  26. bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex());
  27. bool setData(const QModelIndex &index, const ut::types::_tModelDesc &value,
  28. int role = Qt::EditRole);
  29.  
  30.  
  31. static bool parentHasChild(ut::types::tModelBookNodeDesc *&parent,
  32. ut::types::tModelBookNodeDesc *&resultParent,
  33. ut::types::tModelBookNodeDesc *&child,
  34. int& recurse);
  35.  
  36.  
  37. void addChild(ut::types::tModelBookNodeDesc* parent, ut::types::tModelBookNodeDesc child);
  38. void deleteItem(ut::types::tModelBookNodeDesc *item);
  39. void insertParent(ut::types::tModelBookNodeDesc *child, ut::types::tModelBookNodeDesc parent);
  40. void setSelectedItem(ut::types::tModelBookNodeDesc *item);
  41.  
  42. protected:
  43. ut::types::tModelBookNodeDesc *nodeFromIndex(const QModelIndex &index) const;
  44. ut::types::tModelBookNodeDesc *rootNode;
  45. ut::types::tModelBookNodeDesc *parentRootNode;
  46. ut::types::tModelBookNodeDesc *grandParentRootNode;
  47.  
  48.  
  49. public:
  50. mutable QTreeView* m_view;
  51.  
  52. ut::types::tModelBookNodeDesc *selectedItem;
  53.  
  54. };
  55.  
  56.  
  57.  
  58. class DragDropModel : public ModelBookNodeDescModel
  59. {
  60. Q_OBJECT
  61.  
  62. public:
  63. DragDropModel(const QString &full_path, QObject *parent = 0);
  64.  
  65. Qt::ItemFlags flags(const QModelIndex &index) const;
  66.  
  67. bool dropMimeData(const QMimeData *data, Qt::DropAction action,
  68. int row, int column, const QModelIndex &parent);
  69. QMimeData *mimeData(const QModelIndexList &indexes) const;
  70. QStringList mimeTypes() const;
  71. Qt::DropActions supportedDropActions() const;
  72. void removeSelectedIndex();
  73.  
  74. public slots:
  75. void markIndex(const QModelIndex& index);
  76.  
  77.  
  78. protected:
  79. QModelIndex *selectedIndex;
  80. mutable std::vector<ut::types::tModelBookNodeDesc *> nodesToDelete;
  81. mutable ut::types::tModelBookNodeDesc *newParent;
  82.  
  83. };
To copy to clipboard, switch view to plain text mode 

with drag and drop inside the tree view that uses this model there is no problem.

the problem begins when I want to drag an object from outside the view into an element from the view.

the following code replaces the QtreeView witch receive the model

Qt Code:
  1. class DragableDoubleTreeView : public QTreeView
  2. {
  3. Q_OBJECT
  4. public:
  5. DragableDoubleTreeView(QWidget *parent = 0);
  6. void setDoubleTreeView(DoubleTreeView* view);
  7.  
  8. public slots:
  9. void setSelected(const QModelIndex &index);
  10.  
  11. protected:
  12. void mousePressEvent(QMouseEvent *event);
  13. void mouseMoveEvent(QMouseEvent *event);
  14. void dragEnterEvent(QDragEnterEvent *event);
  15. void dragMoveEvent(QDragMoveEvent *event);
  16. void dropEvent(QDropEvent *event);
  17.  
  18. DoubleTreeView *m_doubleTreeView;
  19.  
  20. private:
  21. void startDrag();
  22. QModelIndex *m_modelIndex;
  23.  
  24.  
  25.  
  26. QPoint startPos;
  27. };
  28.  
  29.  
  30. this portion of code interact negatively with the preceding drag and drop model and it does permit to had an element
  31. to the list but not an element into a parent element of the list.
To copy to clipboard, switch view to plain text mode 

if someone has a solution it would thanks him gratefully

Best Regards.
Utopia500