QEvent::KeyPress at QTableWidget is occured only one time



  • The first time, I will participate in this forum.
    thank you.

    my environment is as below.

    OS: Windows 7 professional
    Qt Version: 5.4

    this is question of QTablWidget.

    In the eventFileter function, when I press the key in the cell of QTableWidget,
    QEvent::KeyPress is occured only one time(at the first time), and others is not.
    but QEvent::KeyRelease is occcured every times.

    code is as below.
    @
    bool ValueTable::eventFilter(QObject *obj, QEvent event)
    {
    bool rc = false;
    QKeyEvent
    key;
    QString valstr;
    switch(event->type())
    {
    case QEvent::KeyPress:
    key = (QKeyEvent *)event;
    valstr = key->text();
    qDebug() << "press:" << valstr;
    rc = true;
    break;
    case QEvent::KeyRelease:
    key = (QKeyEvent *)event;
    valstr = key->text();
    qDebug() << "release:" << valstr;
    break;
    @
    here, ValueTable class is inherited QTableWidget.

    For QEditLine, QEvent::KeyPress and QEvent::KeyrRelease is occured everytime when key pressed.

    I need the numeric check of cell(if I press non-numeric key, the key is not appear at the cell.)
    therefore, I need QEvent::KeyPress.

    Please teach me. this is wrong coding or not.

    [edit: added missing coding tags @ SGaist]



    1. Mark your code as code :)

    It is hard to read otherwise.
    Right most icon above editor.
    @
    bool ValueTable::eventFilter(QObject *obj, QEvent event)
    {
    bool rc = false;
    QKeyEvent
    key;
    QString valstr;
    switch(event->type()) {
    case QEvent::KeyPress:
    key = (QKeyEvent *)event;
    valstr = key->text();
    qDebug() << “press:” << valstr;
    rc = true;
    break;
    case QEvent::KeyRelease:
    key = (QKeyEvent *)event;
    valstr = key->text();
    qDebug() << “release:” << valstr;
    break;

    .............
    @

    1. I guess problem is that after first keyPress arrived editing widget for that cell is created.
      And such widget ( like QLineEdit ) receives that event ( you see appropriate char typed for example ) and thus is not propagated.

    So question is what you want to achieve and not how.



  • Phenomenon of eventFileter function is as follows.

    exsample:

    I type next string. "ABC"
    and show qDebug information

    1. cell of QTableWidget
    1. Keypress : A
         press:A
         release:A
         
         As return code of eventFilter is true, A is not appear of input cell area

    2) Keypress : B
        release:B

    QEvent::keypress is not found.

    3) Keypress : C
        release:C

    QEvent::keypress is not found.

    1. QLineEdit ( same eventFilter function)

    1) Keypress : A
       press:A
       release:A

    As return code of eventFilter is true, A is not appear in input area

    2) Keypress : B
       press:B
       release:B

    As return code of eventFilter is true, B is not appear in input area

    1. Keypress : C
        press:C
        release:C

    As return code of eventFilter is true, C is not appear in input area

    I can make numeric check(non-numeric char is not appear in input area) for QLineEdit.
    but I can not make numeric check for QTableWidget.



  • Sorry

    it is hard to see.

    I will check expression method of this .

    I changed before message


Log in to reply
 

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