Add item to top of standard Context Menu at right click
-
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));
}
-
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));
}
@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)); }
-
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));
} -
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));
}@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.