KListWidgetSearchLine Class

This class makes it easy to add a search line for filtering the items in a listwidget based on a simple text search. More...

Header: #include <KListWidgetSearchLine>
CMake: find_package(KF6 REQUIRED COMPONENTS ItemViews)
target_link_libraries(mytarget PRIVATE KF6::ItemViews)
Inherits: QLineEdit

Public Functions

KListWidgetSearchLine(QWidget *parent = nullptr, QListWidget *listWidget = nullptr)
Qt::CaseSensitivity caseSensitive() const
QListWidget *listWidget() const

Public Slots

void clear()
void setCaseSensitivity(Qt::CaseSensitivity cs)
void setListWidget(QListWidget *lv)
virtual void updateSearch(const QString &s = QString())

Protected Functions

virtual bool itemMatches(const QListWidgetItem *item, const QString &s) const

Detailed Description

No changes to the application other than instantiating this class with an appropriate QListWidget should be needed.

Member Function Documentation

[explicit] KListWidgetSearchLine::KListWidgetSearchLine(QWidget *parent = nullptr, QListWidget *listWidget = nullptr)

Constructs a KListWidgetSearchLine with listWidget being the QListWidget to be filtered.

If listWidget is null then the widget will be disabled until a listWidget is set with setListWidget().

Qt::CaseSensitivity KListWidgetSearchLine::caseSensitive() const

Returns if the search is case sensitive.

This defaults to Qt::CaseInsensitive.

See also setCaseSensitive().

[slot] void KListWidgetSearchLine::clear()

Clear line edit and empty hiddenItems, returning elements to listWidget.

[virtual protected] bool KListWidgetSearchLine::itemMatches(const QListWidgetItem *item, const QString &s) const

Returns true if item matches the search s.

This will be evaluated based on the value of caseSensitive().

This can be overridden in subclasses to implement more complicated matching schemes.

QListWidget *KListWidgetSearchLine::listWidget() const

Returns the listWidget that is currently filtered by the search.

See also setListWidget().

[slot] void KListWidgetSearchLine::setCaseSensitivity(Qt::CaseSensitivity cs)

Make the search case sensitive or case insensitive.

See also caseSenstive().

[slot] void KListWidgetSearchLine::setListWidget(QListWidget *lv)

Sets the QListWidget that is filtered by this search line.

If lv is null then the widget will be disabled.

See also listWidget().

[virtual slot] void KListWidgetSearchLine::updateSearch(const QString &s = QString())

Updates search to only make visible the items that match s.

If s is null then the line edit's text will be used.