How to drag QActions from Custom QMenu

  • I have created a custom QMenu class and in that i have added few actions to it. I have to drag the QActions and drop it in a custom widget. I have to override the MousePressEvent, MouseMoveEvent, DragEnterEvent, DragLeaveEvent etc. and i have done it. My Problem is, I can able to drag the menu items, but i cannot drag the actions. from this image shown below, i can able to drag the "Nokia Developer" but i cannot able to drag the "Nokia India" and "Nokia Europe" actions. can anyone please explain me with an example how the drag and drop of menu and actions works and from that how to drag an action from a custom QMenu.

    ! Actions)!


    @#ifndef SUBMENU_H
    #define SUBMENU_H

    #include <QMainWindow>
    #include "ui_SubMenu.h"
    #include "DerivedSubMenu.h"

    class SubMenu : public QMainWindow

    SubMenu(QWidget *parent = 0);

    private slots:
    void wikiForumNokia();
    void DiBoForumNokia();
    void nokiaIndia();
    void nokiaEurope();
    void help();
    void about();

    void createMyMenus();

    Ui::SubMenu ui;

    • DerivedSubMenu *nokiaMenu; //DerivedSubMenu is the Sub class of QMenu
      DerivedSubMenu forumNokiaMenu; //DerivedSubMenu is the Sub class of QMenu
    QAction *menu_nokiaIndiaAction;
    QAction *menu_nokiaEuropeAction;
    QAction *menu_wikiAction;
    QAction *menu_DiBoAction;
    QAction *menu_aboutAction;
    QAction *menu_helpAction;
    QAction *menu_exitAction;


    #endif // SUBMENU_H@


    @#include "SubMenu.h"
    #include <QMenu>
    #include <QMessageBox>
    #include <QDesktopServices>
    #include <QUrl>

    SubMenu::SubMenu(QWidget *parent)
    : QMainWindow(parent)
    setWindowTitle(tr("Sub Menus"));
    //Create memu and sub menu.

    void SubMenu::createMyMenus()

    //add action for help menu.
    menu_helpAction = new QAction(tr("Help"), this);
    connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(help()));
    //add action for about menu.
    menu_aboutAction = new QAction(tr("About"), this);
    connect(menu_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
    /* for nokia menu and its sub menus. */
    //create action Nokia India sub menu item.
    menu_nokiaIndiaAction = new QAction(tr("Nokia India"), this);
        connect(menu_nokiaIndiaAction, SIGNAL(triggered()), this, SLOT(nokiaIndia()));
        //create action Nokia Europe sum menu item
        menu_nokiaEuropeAction = new QAction(tr("Nokia Europe"), this);
    connect(menu_nokiaEuropeAction, SIGNAL(triggered()), this, SLOT(nokiaIndia()));
    //add menu item nokia to main menu
    *nokiaMenu = new DerivedSubMenu(this);* // creating menu with the Sub classed QMenu
    //add action for nokia india sub-menu
    //add action for nokia india sub-menu
    //create action for Discussion Boards sub menu item
    menu_DiBoAction = new QAction(tr("Discussion Boards"), this);
        connect(menu_DiBoAction, SIGNAL(triggered()), this, SLOT(DiBoForumNokia()));
       //create action for Wiki sub menu item
        menu_wikiAction = new QAction(tr("Wiki"), this);
    connect(menu_wikiAction, SIGNAL(triggered()), this, SLOT(wikiForumNokia()));
    //add menu item Nokia Developer to menu item nokia
    • forumNokiaMenu = new DerivedSubMenu(this);* // creating menu with the Sub classed QMenu
      forumNokiaMenu->addMenu("Nokia Developer");
      //forumNokiaMenu = nokiaMenu->addMenu(tr("Nokia Developer"));
      //add action for Discussion Boards sub-menu
      //add action for Wiki sub-menu
    //Add action for exit menu.
    menu_exitAction = new QAction(tr("Exit"), this);
    connect(menu_exitAction, SIGNAL(triggered()), this, SLOT(close()));


    /* handle action for wiki sub-menu item. */
    void SubMenu::wikiForumNokia()

    /* handle action for Discussion Boards sub-menu item. */
    void SubMenu::DiBoForumNokia()

    /* handle action for nokia india sub-menu item. */
    void SubMenu::nokiaIndia()

    /* handle action for nokia europe sub-menu item. */
    void SubMenu::nokiaEurope()

    /* handle action for help menu item. */
    void SubMenu::help()
    QMessageBox::information(this, tr("Help Menu"),tr("This example shows how to create submenu."));

    /* handle action for about menu item. */
    void SubMenu::about()
    QMessageBox::about(this, tr("About Menu"),tr("Testing Sub-Menus."));



Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.