Ask Your Question
1

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

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

AR0x7E7 gravatar image

Hello all,

I'm looking for a way to disable the context menu when right clicking on namedWindow (see http://docs.opencv.org/modules/highgui/doc/qt_new_functions.html 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

Comments

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 -0600 )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 -0600 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-01 02:49:53 -0600 )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 -0600 )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 -0600 )edit
1

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 -0600 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-02 02:14:05 -0600 )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 -0600 )edit
1

@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 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
3

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

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:

opencv\sources\modules\highgui\src\window_QT.cpp

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)
            menu.addAction(a);

        menu.exec(evnt->globalPos());
    }
}

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

void DefaultViewPort::contextMenuEvent(QContextMenuEvent* evnt)
{
    return;
}

recompile opencv, done.

edit flag offensive delete link more

Comments

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

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

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

fupolarbear gravatar image

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

According to < http://docs.opencv.org/modules/highgu... >

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

Comments

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 -0600 )edit
1

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

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

Stats

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

Seen: 5,799 times

Last updated: Jan 03 '15