Skip to content

Commit

Permalink
Fix Suggestion Flickering when Typing
Browse files Browse the repository at this point in the history
setCompleter call setCompletionPrefix on typing which flicker
  • Loading branch information
ShaopengLin committed Oct 18, 2024
1 parent 1f0c138 commit 1bc6c82
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SearchBarLineEdit::SearchBarLineEdit(QWidget *parent) :

/* The items should be less than fetch size to enable scrolling. */
m_completer.setMaxVisibleItems(SuggestionListWorker::getFetchSize() / 2);
setCompleter(&m_completer);
m_completer.setWidget(this);

/* QCompleter's uses default list views, which do not have headers. */
m_completer.setPopup(m_suggestionView);
Expand Down Expand Up @@ -166,9 +166,18 @@ void SearchBarLineEdit::focusInEvent( QFocusEvent* event)
if (event->reason() == Qt::ActiveWindowFocusReason ||
event->reason() == Qt::MouseFocusReason ||
event->reason() == Qt::ShortcutFocusReason) {
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){
setText(index.isValid() ? index.data().toString() : m_searchbarInput);
},
Qt::UniqueConnection);
}
QLineEdit::focusInEvent(event);
}
Expand All @@ -180,6 +189,7 @@ void SearchBarLineEdit::focusOutEvent(QFocusEvent* event)
setText(m_title);
}
deselect();
disconnect(&m_completer, nullptr, this, nullptr);
return QLineEdit::focusOutEvent(event);
}

Expand Down

0 comments on commit 1bc6c82

Please sign in to comment.