QComboBox专注于弹出窗口

时间:2018-06-05 11:28:17

标签: qt focus qcombobox

有2个Qt程序。

一个是普通程序有QComboBox它不是我设计的。

我设计另一个,在启动后隐藏,如果按下KEY_POWER 2秒显示,你可以按两个按钮之间的KEY_TAB / KEY_LEFT / KEY_DOWN 移动焦点

顺便说一下。为了在隐藏时获取键盘输入,如果读取KEY_POWER 2秒显示,我的方法将从线程上的 / dev / input / event0 读取。

void *ThreadMinitorKey(void *arg)
{
    struct input_event key_event;

    fd = open("/dev/input/event0", O_RDONLY);

    while(1) {
        len = read(fd, &key_event, sizeof(key_event));
        if (len != -1 && key_event.type == EV_KEY) {
            if (press_KEW_POWER_2_sec()) {
                g_dialog->show();
            }
        }
    }
}

运行良好

enter image description here 专注于QComoBox

enter image description here 按键盘KEY_POWER 2秒我的窗口显示,焦点在左键。 注意QComboBox,背景从蓝色白色

enter image description here 按KEY_LEFT / KEY_TAB / KEY_RIGHT焦点移动到其他按钮。

运行错误

enter image description here 弹出窗口上的QComboBox

enter image description here 按键盘KEY_POWER 2秒我的窗口显示,焦点在左键。 QComboBox背景仍然蓝色

enter image description here 按KEY_DOWN对QComobox的影响

1 个答案:

答案 0 :(得分:0)

伪触摸输入设备

我找到一条规则,当弹出QComoBox时,如果按下KEY_ENTER或触摸屏,任何窗口都会消失。

因此,在窗口显示之前的任何地方模拟触摸输入点击屏幕。

void pseudo_touch(int fd)
{
    struct input_event event;
    int len;

    event.type = EV_ABS;                        // touch press down
    event.code = ABS_PRESSURE;
    event.value = 1;
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));


    event.type = EV_ABS;                       // post coordinate X,Y make sure don't press any control box
    event.code = ABS_X;                        // ADC range is from 0 to 4095
    event.value = 0x9000;                      // ADC X = 0x9000
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));
    event.type = EV_ABS;
    event.code = ABS_Y;                        // ADC Y = 0xA000
    event.value = 0xa000;
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));

    event.type = EV_SYN;                       // synchronous one event
    event.code = SYN_REPORT;
    event.value = 0;
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));

    event.type = EV_ABS;                       // touch press up
    event.code = ABS_PRESSURE;
    event.value = 0;
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));

    event.type = EV_SYN;                       // synchronous one event
    event.code = SYN_REPORT;
    event.value = 0;
    gettimeofday(&event.time, NULL);
    len = write(fd, &event, sizeof(event));
}

void *ThreadMinitorKey(void *arg)
{
    struct input_event key_event;

    fd       = open("/dev/input/event0", O_RDONLY);   // Keyboard   
    fd_touch = open("/dev/input/event2", O_RDWR);     // Touch

    while(1) {
        len = read(fd, &key_event, sizeof(key_event));
        if (len != -1 && key_event.type == EV_KEY) {
            if (press_KEW_POWER_2_sec()) {
                pseudo_touch(fd_touch);
                g_dialog->show();
            }
        }
    }
}


void DlgShutdown::focusInEvent(QFocusEvent *event)
{
    pBtnCanel->setFocus();
}