Popup menu
-
Hello, I am using mousePressEvent to display an option from my menu, I have a condition where if I press the right button of my mouse, one of the options that I have in my menu is displayed. My problem has been that the menu is displayed in the middle of the screen and I would like it to be displayed below the menu option that I am displayed.
thanks.void MainWindow:: mousePressEvent (QMouseEvent * evento)
{
if(evento->buttons() & Qt::RightButton){
QPoint point = ui->menuArchivo->pos();
ui->menuArchivo->popup(point);
}
} -
Hello, I am using mousePressEvent to display an option from my menu, I have a condition where if I press the right button of my mouse, one of the options that I have in my menu is displayed. My problem has been that the menu is displayed in the middle of the screen and I would like it to be displayed below the menu option that I am displayed.
thanks.void MainWindow:: mousePressEvent (QMouseEvent * evento)
{
if(evento->buttons() & Qt::RightButton){
QPoint point = ui->menuArchivo->pos();
ui->menuArchivo->popup(point);
}
}you want to display the Popup menu at any position of the screen Right ?
-
you want to display the Popup menu at any position of the screen Right ?
@Ketan__Patel__0011
no, I want the actions within a qmenu to appear below the menu option in questionI get this:

I need this:

-
Hi,
From your drawing it seems you want a normal menu to be shown as when you left click on a menu.
Do you mean you only want to change one menu entry when right clicking ?
-
Hi,
From your drawing it seems you want a normal menu to be shown as when you left click on a menu.
Do you mean you only want to change one menu entry when right clicking ?
-
From your second image it seems you have clicked on the Archivo menu. Is that the effect you want ?
Note that this behaviour is going to disturb your users. If I right click somewhere on an application I certainly would think it's a bug that a menu opens like that rather than a contextual menu under the mouse pointer.
-
From your second image it seems you have clicked on the Archivo menu. Is that the effect you want ?
Note that this behaviour is going to disturb your users. If I right click somewhere on an application I certainly would think it's a bug that a menu opens like that rather than a contextual menu under the mouse pointer.
-
What if you call the menu's
popupexec method with no parameters ? -
-
You have to pass the correct global coordinates for the popup to appear as stated in the documentation: Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
-
@Oumayma
You now have at least 3 separate questions going on exactly this topic.It is not nice to make different people respond to the same issue in different threads. It wastes/duplicates their efforts. Is it not reasonable to limit yourself to just one topic for this?
-
@Oumayma
You now have at least 3 separate questions going on exactly this topic.It is not nice to make different people respond to the same issue in different threads. It wastes/duplicates their efforts. Is it not reasonable to limit yourself to just one topic for this?
@JonB I did not notice it before answering this one. Therefore I close this now because it's an exact duplicate of https://forum.qt.io/topic/125327/qmenu-popup/
