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.
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