Context menu position problem
-
@ivanicy
Change themapToGlobal(point)to the desired position if it's not already correct/what you want? -
@JonB point contains the relative position in the QGroupBox and I want to show the contextMenu in the absolute position
@ivanicy
You don't say whether you are claiming thepointreceived in the function is correct? Are you saying it;s always(0, 0), or what?Anyway, if you need to add the
QGroupBoxcoords to it, maybe you need something likegroup->mapToGlobal(), e.g. doesgroup->mapToGlobal(QPoint(0,0))at least put it at top left of group box? -
@ivanicy
You don't say whether you are claiming thepointreceived in the function is correct? Are you saying it;s always(0, 0), or what?Anyway, if you need to add the
QGroupBoxcoords to it, maybe you need something likegroup->mapToGlobal(), e.g. doesgroup->mapToGlobal(QPoint(0,0))at least put it at top left of group box?@JonB Let me try to explain it with a picture.

Now, with my code, when I right click hover a QGroupBox, the context menu appears in the topleft corner and there is a displacement in function of the relative coordinates of the QGroupBox (they are between 0 and QGroupBox size). I need to put the context menu in the right click place.
I hope I explain better this time.
Thank you very much for your time!!!
-
@JonB Let me try to explain it with a picture.

Now, with my code, when I right click hover a QGroupBox, the context menu appears in the topleft corner and there is a displacement in function of the relative coordinates of the QGroupBox (they are between 0 and QGroupBox size). I need to put the context menu in the right click place.
I hope I explain better this time.
Thank you very much for your time!!!
-
@ivanicy
Did you trygroup->mapToGlobal(QPoint(0,0))to see if that places it at top left of group box? -
@JonB This shows the context menu in the topleft corner of the screen, not on the QGroupBox
@ivanicy
May I verify you are tryinggroup->mapToGlobal(QPoint(0, 0))and not justmapToGlobal(QPoint(0, 0))? Because https://doc.qt.io/qt-5/qwidget.html#mapToGlobal statesTranslates the widget coordinate pos to global screen coordinates. For example,
mapToGlobal(QPoint(0,0))would give the global coordinates of the top-left pixel of the widget. -
@ivanicy
May I verify you are tryinggroup->mapToGlobal(QPoint(0, 0))and not justmapToGlobal(QPoint(0, 0))? Because https://doc.qt.io/qt-5/qwidget.html#mapToGlobal statesTranslates the widget coordinate pos to global screen coordinates. For example,
mapToGlobal(QPoint(0,0))would give the global coordinates of the top-left pixel of the widget. -
@JonB This was the solution!!
menuContext->exec(group->mapToGlobal(point));works!!
Thank you very much!
@ivanicy
But that's what I said you needed, i.e.group->mapToGlobal(QPoint(0, 0)), to make it relative togroup, as per the docs! You should not say[Me] Did you try
group->mapToGlobal(QPoint(0,0))to see if that places it at top left of group box?
[You] @JonB This shows the context menu in the topleft corner of the screen, not on the QGroupBoxif you did not copy & paste what I suggested, I suspected you were only trying
mapToGlobal(QPoint(0, 0)), it makes it very hard to help people if they tell you they tried what was suggested but in fact did not! -
@ivanicy
But that's what I said you needed, i.e.group->mapToGlobal(QPoint(0, 0)), to make it relative togroup, as per the docs! You should not say[Me] Did you try
group->mapToGlobal(QPoint(0,0))to see if that places it at top left of group box?
[You] @JonB This shows the context menu in the topleft corner of the screen, not on the QGroupBoxif you did not copy & paste what I suggested, I suspected you were only trying
mapToGlobal(QPoint(0, 0)), it makes it very hard to help people if they tell you they tried what was suggested but in fact did not! -
@JonB Yes, sorry friend, you are right. I didn't read the "group" word the first time. Sorry again