Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best way to duplicate context menu to main menu
Forum Updated to NodeBB v4.3 + New Features

Best way to duplicate context menu to main menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 572 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrzejB
    wrote on last edited by
    #1

    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);
        action->setShortcut(QKeySequence(QKeySequence::Copy));
        connect(action, SIGNAL(triggered()), this, SLOT(copy()));
        action->setEnabled(textCursor().hasSelection());
        selectionMenu->addAction(action);
    
        action = new QAction(tr("&Paste"), this);
        action->setShortcut(QKeySequence(QKeySequence::Paste));
        connect(action, SIGNAL(triggered()), this, SLOT(paste()));
        action->setEnabled(canPaste());
        selectionMenu->addAction(action);
    

    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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved