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.4this 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]
-
- 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;.............
@- 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- cell of QTableWidget
- 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:BQEvent::keypress is not found.
3) Keypress : C
release:CQEvent::keypress is not found.
- QLineEdit ( same eventFilter function)
1) Keypress : A
press:A
release:AAs return code of eventFilter is true, A is not appear in input area
2) Keypress : B
press:B
release:BAs return code of eventFilter is true, B is not appear in input area
- 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.