Ignore standard input
-
I am new to Qt and am trying to replace a character in an input into a QLineEdit field. I have created a QKeyPressed method to get each character.
//----------------------------------------------------------------------------- // eventFilter // Evaluate each character input //----------------------------------------------------------------------------- bool NotebookView::eventFilter(QObject* watched, QEvent* event) { if(watched->inherits("QLineEdit")) { if(event->type() == QEvent::KeyPress) { QKeyEvent* keyCode = static_cast<QKeyEvent*>(event); if((watched == ui->aoEnterVal) || (watched == ui->aoRangeVal)) { m_pCommon->AO_Char(watched, keyCode); } } } return QObject::eventFilter(watched, event); } I am trying to replace the space with an actual value.
case Qt::Key_Space: str = control->objectName().toStdString(); // Don't display Preferences character in Remarks if( ( str.substr ( 2, 6 ) != "Remark" ) || ( str == "mmEnterVal" ) ) { // Fill character from defined character in Preferences editField->insert(Preferences.currChar); } else { editField->insert(" "); } break;
The case works but I am still getting the space in the QLineEdit field. If I replace a character, I need to ignore the actual input character. Any ideas?
-
I tried that and it doesn't even show the QlineEdit entry fields. They are are just gone.
-
I tried that and it doesn't even show the QlineEdit entry fields. They are are just gone.
@gabello306
Could you show the code as you have it now? You haven't literally replaced the onlyreturn QObject::eventFilter(watched, event);
occurrence in your code above with an unconditionalreturn true;
, have you? -
I figured out the problem. Instead of putting the return true at the end, I added it under the AO_Char call. Doing this gets rid of the extra character. See the code below for the change.
//----------------------------------------------------------------------------- // eventFilter // Evaluate each character input //----------------------------------------------------------------------------- bool NotebookView::eventFilter(QObject* watched, QEvent* event) { if(watched->inherits("QLineEdit")) { if(event->type() == QEvent::KeyPress) { QKeyEvent* keyCode = static_cast<QKeyEvent*>(event); if((watched == ui->aoEnterVal) || (watched == ui->aoRangeVal)) { m_pCommon->AO_Char(watched, keyCode); return true; } } } return QObject::eventFilter(watched, event); }
-
-
@gabello306 Yes, well done, that is what @hskoglund meant :) You only return true for those events you have handled/want ignored.