Hi All Experts ,
I am developing an application in which i want a QMenu in which the actions are draggable.
Is there any standard Flag that can be set to the QMenu or QAction .

I have developed a Custom QMenu, in which i have implemented the drag and drop Events.
But the problem is that .. the action is getting added to the end , this happens only when the beforeAction is 0.

Qt Code:
  1. class CustomMenu : public QMenu
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. CustomMenu(QWidget *parent = 0);
  7. bool addActionBool;
  8. bool check;
  9. QAction *beforeAction;
  10. QAction *afterAction;
  11. QAction *action;
  12. QPoint startPos;
  13. int i;
  14. protected:
  15. void mousePressEvent(QMouseEvent *event);
  16. void mouseMoveEvent(QMouseEvent *event);
  17. void dragEnterEvent(QDragEnterEvent *event);
  18. void dragMoveEvent(QDragMoveEvent *event);
  19. void dropEvent(QDropEvent *event);
  20.  
  21. private:
  22. void performDrag();
  23. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. CustomMenu::CustomMenu(QWidget *parent):QMenu(parent)
  2. {
  3. setAcceptDrops(true);
  4. //action = new QAction(this);
  5. }
  6.  
  7. void CustomMenu::mousePressEvent(QMouseEvent *event)
  8. {
  9. if (event->button() == Qt::LeftButton)
  10. {
  11. startPos = event->pos();
  12. action = this->activeAction(); // getting the current active action
  13. }
  14. QMenu::mousePressEvent(event);
  15. }
  16.  
  17. void CustomMenu::mouseMoveEvent(QMouseEvent *event)
  18. {
  19. if (event->buttons() & Qt::LeftButton) {
  20. int distance = (event->pos() - startPos).manhattanLength();
  21. if (distance >= QApplication::startDragDistance())
  22. {
  23. performDrag();
  24. }
  25. }
  26. QMenu::mouseMoveEvent(event);
  27. }
  28.  
  29. void CustomMenu::performDrag()
  30. {
  31. check = action->isChecked();
  32. if (action) {
  33. QMimeData *mimeData = new QMimeData;
  34. mimeData->setText(action->text());
  35.  
  36. QDrag *drag = new QDrag(this);
  37. drag->setMimeData(mimeData);
  38. if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
  39. /*delete action;*/removeAction(action);
  40. }
  41. }
  42.  
  43. void CustomMenu::dragEnterEvent(QDragEnterEvent *event)
  44. {
  45. event->setDropAction(Qt::MoveAction);
  46. event->accept();
  47. }
  48.  
  49. void CustomMenu::dragMoveEvent(QDragMoveEvent *event)
  50. {
  51. event->setDropAction(Qt::MoveAction);
  52. event->accept();
  53. }
  54.  
  55. void CustomMenu::dropEvent(QDropEvent *event)
  56. {
  57. QAction *newAction = new QAction(event->mimeData()->text(),this);
  58. newAction->setCheckable(true);
  59. newAction->setChecked(check);
  60. beforeAction = actionAt(QCursor::pos());
  61. insertAction(beforeAction,newAction); //It appends action if before is 0 or before is not a valid action for this widget. beforeAction is 0 here.
  62. event->setDropAction(Qt::MoveAction);
  63. event->accept();
  64. }
To copy to clipboard, switch view to plain text mode 

where i am going wrong ??