Skip to content

QSearchableTreeWidget#

QSearchableTreeWidget combines a QTreeWidget and a QLineEdit for showing a mapping that can be searched by key.

This is intended to be used with a read-only mapping and be conveniently created using QSearchableTreeWidget.fromData(data). If the mapping changes, the easiest way to update this is by calling setData.

from qtpy.QtWidgets import QApplication

from superqt import QSearchableTreeWidget

app = QApplication([])

data = {
    "none": None,
    "str": "test",
    "int": 42,
    "list": [2, 3, 5],
    "dict": {
        "float": 0.5,
        "tuple": (22, 99),
        "bool": False,
    },
}
tree = QSearchableTreeWidget.fromData(data)
tree.show()

app.exec_()

QSearchableTreeWidget

Qt Class#

QWidget

Methods#

A tree widget for showing a mapping that can be searched by key.

This is intended to be used with a read-only mapping and be conveniently created using QSearchableTreeWidget.fromData(data). If the mapping changes, the easiest way to update this is by calling setData.

The tree can be searched by entering a regular expression pattern into the filter line edit. An item is only shown if its, any of its ancestors', or any of its descendants' keys or values match this pattern. The regular expression follows the conventions described by the Qt docs: https://doc.qt.io/qt-5/qregularexpression.html#details

Attributes:

Name Type Description
tree QTreeWidget

Shows the mapping as a tree of items.

filter QLineEdit

Used to filter items in the tree by matching their key against a regular expression.

fromData(data: Mapping, *, parent: QWidget = None) -> QSearchableTreeWidget classmethod #

Make a searchable tree widget from a mapping.

setData(data: Mapping) -> None #

Update the mapping data shown by the tree.