QSearchableTreeWidget¶
A QTreeWidget that shows a mapping
(such as a dict), with a QLineEdit above it to filter it. Nested mappings and
sequences become branches of the tree, with keys (or indices) in the first
column and values in the second.
The filter is a regular expression: an item is shown if its key or value matches it, or if one of its ancestors' or descendants' does.
Create it with QSearchableTreeWidget.fromData(data). It doesn't watch the
mapping for changes: call setData to show new data.
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.tree.expandAll()
tree.show()
app.exec()
QSearchableTreeWidget
¶
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-6/qregularexpression.html#details
Attributes:
-
tree(QTreeWidget) –Shows the mapping as a tree of items.
-
filter(QLineEdit) –Used to filter items in the tree by matching their key or value against a regular expression.
Subclass of QWidget
QSearchableTreeWidget inherits all of QWidget's methods, signals, and properties. Only those that superqt adds or changes are listed here.
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-6/qregularexpression.html#details
Attributes:
-
tree(QTreeWidget) –Shows the mapping as a tree of items.
-
filter(QLineEdit) –Used to filter items in the tree by matching their key or value against a regular expression.
fromData
¶
fromData(
data: Mapping, *, parent: QWidget = None
) -> QSearchableTreeWidget
Make a searchable tree widget from a mapping.