PDA

View Full Version : QMouseEvent - prevent on statusbar/menubar



DavidY
19th December 2009, 21:13
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:

void Window::contextMenuEvent(QContextMenuEvent *event){

contextMenu->exec(event->globalPos());

}
But it gives me a context menu everywhere

Thanks

DavidY
20th December 2009, 07:43
Never mind, I found a solution


void Window::contextMenuEvent(QContextMenuEvent *event){

QPoint pos = event->pos();
if(!(statusBar()->geometry().contains(pos) || menuBar()->geometry().contains(pos)))
contextMenu->exec(event->globalPos());

}