Skip to content

QtDictTagViewer#

A read-only searchable dictionary viewer for compact metadata tables.

Screenshot#

qt dict tag viewer

Example#

Source: examples/qt_dict_tag_viewer.py

"""QtDictTagViewer."""

from qtpy.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget

from qtextra.config import THEMES
from qtextra.widgets.qt_dict_tag_viewer import QtDictTagViewer

app = QApplication([])

widget = QWidget()
THEMES.apply(widget)

layout = QVBoxLayout(widget)

layout.addWidget(QLabel("QtDictTagViewer"))
viewer = QtDictTagViewer()
viewer.set_items(
    {
        "name": "qtextra",
        "retries": 3,
        "threshold": 0.75,
        "notes": None,
    },
)
viewer.search_edit.setText("th")
layout.addWidget(viewer)

layout.addWidget(QLabel("Read-only searchable table"))
secondary_viewer = QtDictTagViewer()
secondary_viewer.set_items(
    {
        "host": "localhost",
        "port": 5432,
        "timeout": 1.5,
        "cache": None,
    },
)
layout.addWidget(secondary_viewer)

layout.addStretch()
widget.show()

app.exec_()

Notes#

  • Pairs well with the editor variant when you need separate edit and inspect modes.

API#

Qt Class#

QWidget

Signals#

evt_search_changed#

evt_items_changed#

Methods#

Read-only searchable viewer for dictionary values.

clearItems = clear_items class-attribute instance-attribute #

exportDict = export_dict class-attribute instance-attribute #

getItems = items class-attribute instance-attribute #

getValue = get_value class-attribute instance-attribute #

hasItem = has_item class-attribute instance-attribute #

setItems = set_items class-attribute instance-attribute #

clear_items() -> None #

Clear all rows.

export_dict() -> dict[str, DictTagValue] #

Export the displayed dictionary.

get_value(key: str) -> DictTagValue #

Return the value for a key.

has_item(key: str) -> bool #

Return whether a key is present.

items() -> dict[str, DictTagValue] #

Return the current items in table order.

set_items(items: Mapping[str, DictTagValue]) -> None #

Replace all displayed items.