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. Add item to top of standard Context Menu at right click
Forum Updated to NodeBB v4.3 + New Features

Add item to top of standard Context Menu at right click

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • P Offline
    P Offline
    Pauly
    wrote on last edited by
    #1

    In the customMenuRequested slot of right click, I can add item to the end of the standard Context Menu of the qtextedit. But this "I'm new!" item is at the bottom of the context menu after all standard stuff. How can I put it on top above all items in standard Context Menu? Thanks.

    void MainWindow::customMenuRequested( QPoint pos)
    {
    QMenu stdMenu=QMenu(ui->textedit->createStandardContextMenu());
    QMenu *newMenu = stdMenu->addMenu("I'm new!");

    menu->popup(ui->textedit->viewport()->mapToGlobal(pos));
    

    }

    raven-worxR 1 Reply Last reply
    0
    • P Pauly

      In the customMenuRequested slot of right click, I can add item to the end of the standard Context Menu of the qtextedit. But this "I'm new!" item is at the bottom of the context menu after all standard stuff. How can I put it on top above all items in standard Context Menu? Thanks.

      void MainWindow::customMenuRequested( QPoint pos)
      {
      QMenu stdMenu=QMenu(ui->textedit->createStandardContextMenu());
      QMenu *newMenu = stdMenu->addMenu("I'm new!");

      menu->popup(ui->textedit->viewport()->mapToGlobal(pos));
      

      }

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Pauly
      Untested:

      void MainWindow::customMenuRequested( QPoint pos)
      {
         QMenu* stdMenu= ui->textedit->createStandardContextMenu();
         QMenu* newMenu = new QMenu("I'm new!");
         stdMenu->insertAction( stdMenu->actions().first(), newMenu );
      
         menu->popup(ui->textedit->viewport()->mapToGlobal(pos));
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Pauly
        wrote on last edited by
        #3

        I think you meant insertMenu... It works like a charm. Thanks a lot!

        @raven-worx said in Add item to top of standard Context Menu at right click:

        void MainWindow::customMenuRequested( QPoint pos)
        {
        QMenu* stdMenu= ui->textedit->createStandardContextMenu();
        QMenu* newMenu = new QMenu("I'm new!");
        stdMenu->insertAction( stdMenu->actions().first(), newMenu );

        menu->popup(ui->textedit->viewport()->mapToGlobal(pos));
        }

        raven-worxR 1 Reply Last reply
        0
        • P Pauly

          I think you meant insertMenu... It works like a charm. Thanks a lot!

          @raven-worx said in Add item to top of standard Context Menu at right click:

          void MainWindow::customMenuRequested( QPoint pos)
          {
          QMenu* stdMenu= ui->textedit->createStandardContextMenu();
          QMenu* newMenu = new QMenu("I'm new!");
          stdMenu->insertAction( stdMenu->actions().first(), newMenu );

          menu->popup(ui->textedit->viewport()->mapToGlobal(pos));
          }

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Pauly said in Add item to top of standard Context Menu at right click:

          I think you meant insertMenu... It works like a charm. Thanks a lot!

          yep indeed. great.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

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