From 68a7e3b795be57e933159b095eafb895b45f1763 Mon Sep 17 00:00:00 2001 From: luddens Date: Tue, 18 Jun 2019 16:44:35 +0200 Subject: [PATCH] Fix bug signal activated not emitted Qt seems to disconnect every signal handlers (signal emitted by QCompleter) of QLineEdit (the SearchBar) every time the QLineEdit loses the focus, so it has to be connected every time it gains the focus with the mouse. --- src/searchbar.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 34fdacc..c12ac3d 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -73,8 +73,6 @@ SearchBar::SearchBar(QWidget *parent) : m_completer.popup()->setStyleSheet(style); connect(this, &QLineEdit::textEdited, this, &SearchBar::updateCompletion); - connect(&m_completer, QOverload::of(&QCompleter::activated), - this, &SearchBar::openCompletion); connect(KiwixApp::instance(), &KiwixApp::currentTitleChanged, this, &SearchBar::on_currentTitleChanged); } @@ -87,8 +85,11 @@ void SearchBar::on_currentTitleChanged(const QString& title) void SearchBar::focusInEvent( QFocusEvent* event) { - if (event->reason() == Qt::MouseFocusReason) + if (event->reason() == Qt::MouseFocusReason) { clear(); + connect(&m_completer, QOverload::of(&QCompleter::activated), + this, &SearchBar::openCompletion); + } QLineEdit::focusInEvent(event); m_button.set_searchMode(true); }