Ask Your Question

Opencv 2.4.9 highgui +qt: howto disable menu (right click context)

asked 2014-04-30 16:09:09 -0500

AR0x7E7 gravatar image

Hello all,

I'm looking for a way to disable the context menu when right clicking on namedWindow (see for clarification)

The reason is, I want to use the right mouse button for some user interaction but the menu keeps popping up and is therefore disturbing havily.

I also tried to identifiy the part of opencv source code (QT_window.cpp) where the callback function with rightbuttonup is set - as you might guess, unsuccessfully.

Thank you for any help.

Kind regards AR

edit retag flag offensive close merge delete


Just dont build with Qt support or isn't that an option? You can still use the windows but the other functions get isolated, like the right mouse click.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-01 02:34:07 -0500 )edit

Hi StevenPuttermans and thanks for your reply, unfortunately I'm in need of the Qt enhanced GUI functionalities (like resize window, zoom in/out, take picture). Therefore, building opencv with qt is a must.

AR0x7E7 gravatar imageAR0x7E7 ( 2014-05-01 02:49:07 -0500 )edit

Then I am afraid you will need another hotkey than the mouse button :P

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-01 02:49:53 -0500 )edit

Yes, this might be plan B - however, I'm a programmer, this whole software is open source, so In my opinion it has to be possible and it might just be a few loc in need to be commented (i.e. the switch statement which handles the mousrightbuttonclick event triggering the context menu to appear) and my mission will be accomplished :P

AR0x7E7 gravatar imageAR0x7E7 ( 2014-05-01 02:53:32 -0500 )edit

That is true :) it is probably possible to find the correct file in the source code.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-01 02:56:39 -0500 )edit

so I found the appropriate part of code to comment =) Unfortunately, I have to wait until tomorrow until I can answer my own question :D

AR0x7E7 gravatar imageAR0x7E7 ( 2014-05-01 08:12:54 -0500 )edit

Ok, do post your solution, since it will help others tackling the same problem.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-02 02:14:05 -0500 )edit

StevenPuttemans, can you please accept the answer below and close the question? I lack sufficient reputation ;D Of course you can check my solution first.

AR0x7E7 gravatar imageAR0x7E7 ( 2014-05-03 02:15:10 -0500 )edit

@AR0x7E7, only you can accept it as solved, but we can upvote it, until you get enough rep. ;)

berak gravatar imageberak ( 2014-05-03 02:38:38 -0500 )edit

3 answers

Sort by ยป oldest newest most voted

answered 2014-05-03 02:13:07 -0500

AR0x7E7 gravatar image

In order to deactivate the right click context menu using opencv 2.4.9 namedWindow with Qt 5.2.1 search for file:


find the following function (usually line 2514):

void DefaultViewPort::contextMenuEvent(QContextMenuEvent* evnt)
    if (centralWidget->vect_QActions.size() > 0)
        QMenu menu(this);

        foreach (QAction *a, centralWidget->vect_QActions)


set it to (alternatively just comment the inside of function):

void DefaultViewPort::contextMenuEvent(QContextMenuEvent* evnt)

recompile opencv, done.

edit flag offensive delete link more


hi, how can I recompile opencv on a mac / Xcode? Thx

scharti gravatar imagescharti ( 2014-09-08 13:35:43 -0500 )edit

answered 2015-01-03 03:10:27 -0500

fupolarbear gravatar image

updated 2015-01-03 03:13:26 -0500

According to < >

use para 'CV_GUI_NORMAL' can solve your problem, following is the code from the official guide (url above):

cvNamedWindow("main2",CV_WINDOW_AUTOSIZE | CV_GUI_NORMAL);

the CV_GUI_NORMAL can disable the useless and annoying toolbox.

and I don't think recompiling OpenCV is a good idea.

edit flag offensive delete link more


This should be the best answer. It is more practical and easier to porting to different environment than recompiling OpenCV.

ZheH gravatar imageZheH ( 2020-02-21 16:07:01 -0500 )edit

answered 2014-06-10 12:43:16 -0500

alrojas gravatar image

Hi, think the "right way" is set namedWindow flag with << CV_WINDOW_OPENGL + CV_WINDOW_AUTOSIZE >> :P

edit flag offensive delete link more

Question Tools


Asked: 2014-04-30 16:09:09 -0500

Seen: 4,828 times

Last updated: Jan 03 '15