0
votes

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));
}
1

1 Answers

0
votes

Found the solution!

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