Results 1 to 2 of 2

Thread: QMouseEvent - prevent on statusbar/menubar

  1. #1
    Join Date
    Dec 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QMouseEvent - prevent on statusbar/menubar

    I have a custom widget which reimplements QMainWindow. It has a statusbar and menubar and the main window area between. I want a context menu to appear in the main area when right clicked but not if the right click is on the status bar or menubar. How do I exclude them? I was thinking of checking the position of the click and seeing if that was within the allowed area but I'm not sure how.

    Right now I'm using this:
    Qt Code:
    1. void Window::contextMenuEvent(QContextMenuEvent *event){
    2.  
    3. contextMenu->exec(event->globalPos());
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 
    But it gives me a context menu everywhere

    Thanks
    Last edited by DavidY; 19th December 2009 at 23:52.

  2. #2
    Join Date
    Dec 2009
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMouseEvent - prevent on statusbar/menubar

    Never mind, I found a solution

    Qt Code:
    1. void Window::contextMenuEvent(QContextMenuEvent *event){
    2.  
    3. QPoint pos = event->pos();
    4. if(!(statusBar()->geometry().contains(pos) || menuBar()->geometry().contains(pos)))
    5. contextMenu->exec(event->globalPos());
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by DavidY; 20th December 2009 at 07:53.

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.