MacOS ignore keyevent filters



  • I need to prevent entering non HEX symbols into QLineEdit, but default setInputMask work not really good for me.
    So I tried to write it by myself:
    @bool LineEdit::eventFilter(QObject *obj, QEvent *event)
    {
    if (obj == this) {
    if (event->type() == QEvent::KeyPress)
    {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    if (!keyEvent->text().contains(QRegExp("[^a-fA-F0-9]")) && !keyEvent->text().isEmpty())
    // bruteforce way
    // if (keyEvent->key() == Qt::Key_A
    // || keyEvent->key() == Qt::Key_B
    // || keyEvent->key() == Qt::Key_C
    // || keyEvent->key() == Qt::Key_D
    // || keyEvent->key() == Qt::Key_E
    // || keyEvent->key() == Qt::Key_F
    // || keyEvent->key() == Qt::Key_0
    // || keyEvent->key() == Qt::Key_1
    // || keyEvent->key() == Qt::Key_2
    // || keyEvent->key() == Qt::Key_3
    // || keyEvent->key() == Qt::Key_4
    // || keyEvent->key() == Qt::Key_5
    // || keyEvent->key() == Qt::Key_6
    // || keyEvent->key() == Qt::Key_7
    // || keyEvent->key() == Qt::Key_8
    // || keyEvent->key() == Qt::Key_9)
    {
    this->setText(this->text() + keyEvent->text().toUpper());
    return true;
    } else {
    return true;
    }
    }
    }
    return QLineEdit::eventFilter(obj, event);
    }@

    On Linux all works fine, but on Mac I can enter cyrillic symbols. And I can't prevent it in any ways.
    And any of methods I trying, can't prevent it.

    Is it Mac bug?

    Here is minimal compilable example:
    http://rghost.ru/download/41304261/a1f3826a4a0964e3446e24554f63f95082e4e6c8/keyevent-test.zip


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.