Skip to content

Commit

Permalink
Fix Suggestion Flickering when Typing
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaopengLin committed Sep 4, 2024
1 parent c6a4611 commit 777c207
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :

/* +2 for fulltext and load more */
m_completer.setMaxVisibleItems(SuggestionListWorker::getFetchSize() + 2);
setCompleter(&m_completer);
m_completer.setWidget(this);

/* QCompleter's uses default list views, which do not have headers. */
auto treeView = new QTreeView();
Expand Down Expand Up @@ -143,9 +143,20 @@ void SearchBarLineEdit::focusInEvent( QFocusEvent* event)
event->reason() == Qt::MouseFocusReason ||
event->reason() == Qt::ShortcutFocusReason ||
event->reason() == Qt::PopupFocusReason) {
connect(&m_completer, QOverload<const QString &>::of(&QCompleter::activated),
this, &QLineEdit::setText,Qt::UniqueConnection);

connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, QOverload<const QModelIndex &>::of(&SearchBarLineEdit::openCompletion),
Qt::UniqueConnection);

connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::highlighted),
this, [=](const QModelIndex &index){
if (index.isValid() && !m_suggestionModel.isLoadMoreIndex(index))
setText(index.data().toString());
else
setText(m_searchbarInput);
}, Qt::UniqueConnection);
}
QLineEdit::focusInEvent(event);
}
Expand All @@ -156,6 +167,7 @@ void SearchBarLineEdit::focusOutEvent(QFocusEvent* event)
if (event->reason() == Qt::MouseFocusReason && text().isEmpty()) {
setText(m_title);
}
disconnect(&m_completer, nullptr, this, nullptr);
deselect();
return QLineEdit::focusOutEvent(event);
}
Expand Down

0 comments on commit 777c207

Please sign in to comment.