From 5860e81ff39c84523de87eadf1fb4a5a181a189d Mon Sep 17 00:00:00 2001 From: yifang Date: Thu, 16 Dec 2021 22:46:21 +0800 Subject: [PATCH] typingEvent fix,double characters when focus --- mainwindow.cc | 13 +++++++------ scanpopup.cc | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index 1d7c658e..002f6bdf 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2583,7 +2583,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) else if ( obj == wordList ) { - if ( ev->type() == QEvent::KeyPress ) + if (ev->type() == QEvent::KeyPress || ev->type() == QEvent::ShortcutOverride) { QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); @@ -2634,7 +2634,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) } else if (obj == ui.dictsList) { - if ( ev->type() == QEvent::KeyPress ) + if ( ev->type() == QEvent::KeyPress || ev->type() == QEvent::ShortcutOverride) { QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); @@ -2768,10 +2768,11 @@ void MainWindow::typingEvent( QString const & t ) if( translateLine->isEnabled() ) { - //translateLine->setFocus(); - // Escaping the typed-in characters is the user's responsibility. - setTranslateBoxTextAndClearSuffix( t, WildcardsAreAlreadyEscaped, EnablePopup ); - translateLine->setCursorPosition( t.size() ); + translateLine->clear(); + translateLine->setFocus(); + // Escaping the typed-in characters is the user's responsibility. + // setTranslateBoxTextAndClearSuffix( t, WildcardsAreAlreadyEscaped, EnablePopup ); + // translateLine->setCursorPosition( t.size() ); } } } diff --git a/scanpopup.cc b/scanpopup.cc index 4a16d75d..e911d67c 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -856,9 +856,10 @@ void ScanPopup::typingEvent( QString const & t ) } else { - ui.translateBox->translateLine()->setFocus(); - ui.translateBox->setText( t, true ); - ui.translateBox->translateLine()->setCursorPosition( t.size() ); + ui.translateBox->translateLine()->clear(); + ui.translateBox->translateLine()->setFocus(); + // ui.translateBox->setText( t, true ); + // ui.translateBox->translateLine()->setCursorPosition( t.size() ); } }