Important: Please read the Qt Code of Conduct -

Best way to duplicate context menu to main menu

  • In context menu actions are generated on show in CodeEditor::contextMenuEvent, but I don't know how works shortucts before showing of context menu.
    My piece of code:

        action = new QAction(tr("&Copy"), this);
        connect(action, SIGNAL(triggered()), this, SLOT(copy()));
        action = new QAction(tr("&Paste"), this);
        connect(action, SIGNAL(triggered()), this, SLOT(paste()));

    Now, I want copy Copy,Paste and other actions to main menu. How do it? I must have copy action for all open editors and fill main menu on show? or main menu actions call MainWindow proxy procedure with parameter, which call actions for editor?

  • Qt Champions 2017

    Do you want to the same action to be displayed for menu & context menu ? Is this you want ? If yes, simply add action object to both main menu and addAction for widget.

  • Lifetime Qt Champion


    If you want to use the same actions in multiple places, make them private members of your class and create them in your main window constructor.

    Then re-use the same actions for your contextual menu.

Log in to reply