Skip to content

QtTagEditor#

A lightweight tag entry widget for adding, removing, and deduplicating short labels.

Screenshot#

qt tag editor

Example#

Source: examples/qt_tag_editor.py

"""QtTagEditor."""

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

from qtextra.config import THEMES
from qtextra.widgets.qt_tag_editor import QtTagEditor

app = QApplication([])

widget = QWidget()
THEMES.apply(widget)

layout = QVBoxLayout(widget)

layout.addWidget(QLabel("QtTagEditor"))
tag_editor = QtTagEditor()
tag_editor.add_tags(["alpha", "beta", "release"])
layout.addWidget(tag_editor)

layout.addWidget(QLabel("Scrollable QtTagEditor"))
scroll_editor = QtTagEditor(flow=False, placeholder="Type a tag and press Enter")
scroll_editor.add_tags(["project", "desktop", "qt", "widgets", "search", "tags"])
layout.addWidget(scroll_editor)

layout.addStretch()
widget.show()

app.exec_()

Notes#

  • Supports both flow and horizontally scrollable layouts depending on available space.

API#

Qt Class#

QWidget

Signals#

evt_text_changed#

evt_tag_added#

evt_tag_removed#

evt_tags_changed#

Methods#

Editor for managing a collection of short text tags.

addCurrentText = add_current_text class-attribute instance-attribute #

addTag = add_tag class-attribute instance-attribute #

addTags = add_tags class-attribute instance-attribute #

clearTags = clear_tags class-attribute instance-attribute #

getTags = tags class-attribute instance-attribute #

hasTag = has_tag class-attribute instance-attribute #

removeTag = remove_tag class-attribute instance-attribute #

setTags = set_tags class-attribute instance-attribute #

add_current_text() -> list[str] #

Add the current input contents as one or more tags.

add_tag(text: str) -> bool #

Add a single tag.

add_tags(tags: list[str]) -> list[str] #

Add multiple tags and return the tags that were added.

clear_tags(emit_signal: bool = True) -> None #

Remove all tags.

has_tag(text: str) -> bool #

Return whether the tag is present.

remove_tag(text: str) -> bool #

Remove a tag by value.

set_tags(tags: list[str]) -> None #

Replace all tags.

tags() -> list[str] #

Return the current tags in display order.