Why Does A Right Click Open A Drop Down Menu In My Opencv Imshow() Window?
Solution 1:
In Python, you can pass the cv2.WINDOW_GUI_NORMAL
flag to namedWindow()
to disable the dropdown (flag is supported only if you have Qt backend):
cv2.namedWindow("window_name", cv2.WINDOW_GUI_NORMAL)
And then call
cv2.imshow("window_name", img)
Link to documentation of the namedWindow
function is here.
Solution 2:
You're using the Qt highgui
backend, which looks like it forces the right-click context menu without the ability to disable it without recompilation of opencv. If you didn't see it before, it's likely you were using a different backend.
If you prefer using Qt and don't mind altering the opencv source slightly and rebuilding, it looks like changing the DefaultViewPort::contextMenuEvent()
method in file modules/highgui/src/window_QT.cpp
to skip building the menu and just returning will probably work (or else have it optionally build the menu due to some flag that you add). Currently, the Qt highgui backend auto-creates the menu using whatever actions are available in the regular menu.
Here's a link to the method in the current opencv master branch as of 2019-06-18:
which has this code:
voidDefaultViewPort::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());
}
}
An alternative that might work without recompilation might be to use left dragging for selection while checking for an additional modifier key being held down (like shift or ctrl).
I haven't actually tested either of these approaches BTW, so good luck! :-)
UPDATE:
If you still want Qt but don't need the fancy menu options and extra behavior and such, it looks like you can add the CV_GUI_NORMAL
flag when creating the window to disable the CV_GUI_EXPANDED
Qt features.
Post a Comment for "Why Does A Right Click Open A Drop Down Menu In My Opencv Imshow() Window?"