Handle QmouseEvent for rightClickEvent and rightClickEvent+moveEvent seperately

  • Hello,

    I want to show a menu on right click and use right mouse move for moving stuff around.

    So I've implemented both methods in :

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);.

    However now, when I move around, also the menu opens.
    So how can I distinguish between both cases.

    One option I thought of is using a QTimer to trigger the menu, that gets canceled by the move but is there a better option?

    Thanks in advance

  • @gde23
    Where are you doing all of this? You're just supposed to attach menus to widgets' QContextMenuEvent, QWidget::contextMenuEvent(QContextMenuEvent *event), etc.

    Oh, I think I see what you mean. Start by being more specific about "use right mouse move for moving stuff around.". Presumably you are talking about right mouse down and then drag/move around, else it wouldn't be interfering with the right-click context menu? So the trouble with your intention is that at right-mouse-down you still don't know whether to show a menu or start a drag? I don't think this is a good idea, I can't think of an application which deals with right-mouse-down ambiguously like this? I would try to think of one before you adopt this behaviour.

Log in to reply