mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
fix: press enter event handled in translateline
This commit is contained in:
parent
d4f19cf4cd
commit
05fa73128b
|
@ -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();
|
||||
|
|
|
@ -36,6 +36,7 @@ private slots:
|
|||
|
||||
private:
|
||||
QLineEdit * translate_line;
|
||||
bool selectedItem = false;
|
||||
bool m_popupEnabled;
|
||||
QCompleter * completer;
|
||||
QStringList words;
|
||||
|
|
Loading…
Reference in a new issue