Results 1 to 14 of 14

Thread: contextMenuEvent

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default contextMenuEvent

    Hi, I implemeted this below to have a mouse menu; problem: when I click and move mouse and then release, menu appear; If I click and move I traslate the scene; and when I release mouse, i don't want menu mouse appear; how this? (is there a QT way?) thanks
    Qt Code:
    1. void MyWidget::contextMenuEvent(QContextMenuEvent* event)
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: contextMenuEvent

    Anyone know this?
    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: contextMenuEvent

    Could you explain what the exact problem is? What you expect and what you get?

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: contextMenuEvent

    The problem is this: if I click right mouse contextMenuEvent is called and a popupmousemenu is drawn; problem is if I press mouse dx and move mouse my scene will be rotate; after this, when I release mouse, contextMenuEvent is called: and this isn't right; mouse menu have to be drawn only if I click (in a point) and release immediately (without move).are u understand?
    Regards

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: contextMenuEvent

    Catch mouse button press/release events, compare press/release offset, show the context menu only if the offset was in allowed range.
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: contextMenuEvent

    As far as I know the context menu on Windows is shown upon release of the button (at least in Qt4). Do you receive the event after pressing the button?

    How does your menu event handler look like?

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: contextMenuEvent

    wysota, yep, release event comes before the context menu event. As far as I understood correctly, he wants to avoid showing of context menu if mouse was moved during press and release.

    mickey, the context menu event is sent regardless of that if the mouse was moved or not. You will have to examine the possible movement manually.
    J-P Nurmi

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: contextMenuEvent

    I think you should just ignore the event based on the geometry, content or simply previous mouse events.

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: contextMenuEvent

    event is called when I release mouse! But If I pressed dx button for do traslation, menu mustn't appear!
    Regards

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: contextMenuEvent

    Quote Originally Posted by mickey
    event is called when I release mouse! But If I pressed dx button for do traslation, menu mustn't appear!
    Yes, we understood the problem. Here's a couple of pseudo algorithms to solve it. The choice is yours:
    Qt Code:
    1. mousePressEvent:
    2. pressPoint = mouse press event's position
    3.  
    4. contextMenuEvent:
    5. if distance between context menu event's position and pressPoint is less than something
    6. show context menu
    7. else do nothing
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. mousePressEvent:
    2. pressPoint = mouse press event's position
    3.  
    4. mouseReleaseEvent:
    5. if distance between mouse release event's position and pressPoint is less than something
    6. showContextMenu = true
    7. else
    8. showContextMenu = false
    9.  
    10. contextMenuEvent:
    11. if showContextMenu
    12. show context menu
    13. else do nothing
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. mousePressEvent:
    2. showContextMenu = true
    3.  
    4. mouseMoveEvent:
    5. showContextMenu = false
    6.  
    7. contextMenuEvent:
    8. if showContextMenu
    9. show context menu
    10. else do nothing
    To copy to clipboard, switch view to plain text mode 
    or ....
    J-P Nurmi

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: contextMenuEvent

    Hmm... could you provide a minimal compilable example which reproduces the problem? Because as for now we're talking about a bit abstract behaviour.

  12. #12
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: contextMenuEvent

    i think so long...but Do I have use some flag to do this?when right mouse button do some things (translate, change color of scene where I pick (only if I have a pushbutton down). so if traslate or changing color (it works), when I releae mouse appear menu; I can follow advice of jpn (for every things I set a flags menuContext=false), but I hoped find a Qt way....such as ignore() (but I haven't idea how use it):..
    Regards

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: contextMenuEvent

    If you do, remember to reimplement also the release event to clear values which were set in previous handlers.

  14. #14
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: contextMenuEvent

    I'm trying this; with mouseMoving flag it works; but I wonder how use ignore() function
    Qt Code:
    1. void MyWidget::contextMenuEvent(QContextMenuEvent* e) {
    2. if (mouseMoving) {mouseMoving = false; return;}
    3. //if (mouseMoving) e->ignore(); //Must I use ignore() in that way?
    To copy to clipboard, switch view to plain text mode 
    Where do I have to use ignore? and how cal it? thanks
    Regards

Similar Threads

  1. contextMenuEvent has issues since 4.1.3
    By momesana in forum Qt Programming
    Replies: 9
    Last Post: 31st May 2006, 17:27
  2. Replies: 4
    Last Post: 17th February 2006, 14:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.