Skip to content

QT backend: cv::waitKey() and cv::waitKeyEx() do not capture arrow keys once you click on the image or press TAB #20215

@pajos-c

Description

@pajos-c
System information (version)
Detailed description

Hi,
cv::waitKey() and cv::waitKeyEx() do not capture arrow keys once you click on the image or press TAB. The sample code prints pressed key. When you run it, arrow keys are printed as expected, but if you then click on the image inside the window and press those keys again they won't get printed. Same happens when you press TAB. Moreover, first pressing of TAB prints nothing, but subsequent presses do print. Numpad arrow keys are affected as well. Other keys work fine.

This happens only when built with WITH_QT=ON, otherwise it works as expected.
Complete cmake configuration with WITH_QT=ON: cmake_configure_output.txt. Same configuration with with WITH_QT=OFF works fine.

I found similar issue with TAB (but not mouse click) #9901, but it was closed with: "Looks like "QT" UI backend has been enabled in your OpenCV build. TAB can be preserved to switch between "UI elements" in that case." Which is not the case because pressing TAB does not move focus to control buttons on the top.

This is quite problematic as pip's opencv-python gets built with QT backend...

Steps to reproduce
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <cstdio>
#include <iostream>

using namespace std;

int main( int argc, char** argv )
{
    cv::Mat img = cv::Mat::zeros(cv::Size(300, 300), CV_8UC1);

    while (true)
    {
        cv::imshow("win", img);
        int key = cv::waitKey(0) & 0xFF;
        cout << key << endl;
        if (key == 'q') {
            break;
        }
    }

    return 0;
}
  1. Press arrow keys; works fine.
  2. Click with mouse on the image or press TAB.
  3. Now pressing arrow key does nothing. Other keys work just fine.
Issue submission checklist
  • [ x ] I report the issue, it's not a question
  • [ x ] I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • [ x ] I updated to latest OpenCV version and the issue is still there
  • [ x ] There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions