mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-05 00:24:06 +00:00
fix: press enter event handled in translateline
This commit is contained in:
parent
08816a0c64
commit
54c8bd56f7
|
@ -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