[PYTHON] Easily implement ItemView incremental search with PySide

Although not well known, Qt comes standard with an incremental search mechanism for ItemView.

QAbstractItemView::keyboardSearch

With this feature, you can switch item selections each time you press the keyboard on ItemView without doing anything. However, the current search word is hidden and difficult to understand, and IME is not supported, so Japanese item search is not possible.

Just create QLineEdit etc. like a conventional search bar and connect appropriate slots.

line_edit = QLineEdit()
tree_view = QTreeView()

def _search(search):
    tree_view.keyboardSearch("")        # search clear
    tree_view.keyboardSearch(search)

line_edit.textChanged.connect(_search)
line_edit.returnPressed.connect(lambda:_search(line_edit.text()))

The empty string is set for keyboardSearch to reset the search buffer. Of course, you can also search in Japanese.

Demerit

It's easy, but it still has its disadvantages.

I can't find items that have collapsed in QTreeView. Since this is a Qt specification, call expandAll () in advance.

Recommended Posts

Easily implement ItemView incremental search with PySide
Easily implement subcommands with python click
Easily implement login authentication function with Laravel
Easily daemonized with Supervisor
Sequential search with Python
Implement FReLU with tf.keras
Binary search with python
Easily beep with python
Binary search with Python3
Database search with db.py
[Causal search / causal inference] Implement a Bayesian network with Titanic data