Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QEvent::KeyPress at QTableWidget is occured only one time

QEvent::KeyPress at QTableWidget is occured only one time

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    H-kata
    wrote on last edited by
    #1

    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 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2
      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        H-kata
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          H-kata
          wrote on last edited by
          #4

          Sorry

          it is hard to see.

          I will check expression method of this .

          I changed before message

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved