fix: press enter event handled in translateline

This commit is contained in:
YiFang Xiao 2023-09-10 22:06:41 +08:00
parent 08816a0c64
commit 54c8bd56f7
2 changed files with 26 additions and 2 deletions

View file

@ -57,6 +57,22 @@ TranslateBox::TranslateBox( QWidget * parent ):
translate_line->setText( text );
emit returnPressed();
} );
connect( completer,
QOverload< const QString & >::of( &QCompleter::highlighted ),
translate_line,
[ & ]( const QString & text ) {
selectedItem = true;
} );
connect( translate_line,
&QLineEdit::returnPressed,
[ this ]() {
if ( selectedItem )
return;
emit returnPressed();
} );
}
void TranslateBox::setText( const QString & text, bool showPopup )
@ -88,14 +104,21 @@ void TranslateBox::setModel( QStringList & _words )
connect( completer,
QOverload< const QString & >::of( &QCompleter::activated ),
translate_line,
[ & ]( const QString & text) {
translate_line->setText(text);
[ & ]( const QString & text ) {
translate_line->setText( text );
emit returnPressed();
} );
connect( completer,
QOverload< const QString & >::of( &QCompleter::highlighted ),
translate_line,
[ & ]( const QString & text ) {
selectedItem = true;
} );
}
void TranslateBox::showPopup()
{
selectedItem = false;
if ( m_popupEnabled ) {
completer->popup()->show();
completer->complete();

View file

@ -36,6 +36,7 @@ private slots:
private:
QLineEdit * translate_line;
bool selectedItem = false;
bool m_popupEnabled;
QCompleter * completer;
QStringList words;