QtSearchPanel#
Reusable search and replace panel for text editors and plain-text views.
Screenshot#

Example#
Source: examples/qt_search_panel.py
"""QtSearchPanel."""
from qtpy.QtWidgets import QApplication, QLabel, QPlainTextEdit, QVBoxLayout, QWidget
from qtextra.config import THEMES
from qtextra.widgets.qt_text_search import QtSearchPanel
app = QApplication([])
widget = QWidget()
THEMES.apply(widget)
layout = QVBoxLayout(widget)
editor = QPlainTextEdit()
editor.setPlainText(
"QtSearchPanel is useful for common desktop workflows.\n"
"Search, navigate, and replace text from a shared reusable panel.\n"
"This example wires the panel to a text area in a minimal way.",
)
status = QLabel("Type into the search box to search the editor.")
search_panel = QtSearchPanel()
search_panel.set_target_editor(editor)
search_panel.setSearchText("search")
search_panel.evt_search_changed.connect(lambda text: status.setText(f"Searching for: {text or '<empty>'}"))
layout.addWidget(search_panel)
layout.addWidget(editor)
layout.addWidget(status)
widget.resize(720, 320)
widget.show()
app.exec_()
Notes#
- This widget is a good default when you want shared editor search behavior across the app.
API#
Qt Class#
Signals#
evt_options_changed#
evt_find_previous#
evt_find_next#
evt_search_changed#
evt_closed#
evt_replace_one#
evt_replace_all#
Methods#
Reusable find and replace panel.
case_sensitive: bool
property
#
Return whether case matching is enabled.
closePanel = close_panel
class-attribute
instance-attribute
#
findNext = find_next
class-attribute
instance-attribute
#
findPrevious = find_previous
class-attribute
instance-attribute
#
regex: bool
property
#
Return whether regex mode is enabled.
replaceAll = replace_all
class-attribute
instance-attribute
#
replaceOne = replace_one
class-attribute
instance-attribute
#
replaceText = replace_text
class-attribute
instance-attribute
#
searchOptions = search_options
class-attribute
instance-attribute
#
searchText = search_text
class-attribute
instance-attribute
#
setMatchCount = set_match_count
class-attribute
instance-attribute
#
setReplaceText = set_replace_text
class-attribute
instance-attribute
#
setReplaceVisible = set_replace_visible
class-attribute
instance-attribute
#
setSearchText = set_search_text
class-attribute
instance-attribute
#
setTargetEditor = set_target_editor
class-attribute
instance-attribute
#
whole_word: bool
property
#
Return whether whole-word matching is enabled.
clear() -> None
#
Clear the search and replace contents.
close_panel() -> None
#
Hide the panel and emit a close signal.
find_next() -> None
#
Emit a request to navigate to the next match.
find_previous() -> None
#
Emit a request to navigate to the previous match.
replace_all() -> None
#
Emit a request to replace all matches.
replace_one() -> None
#
Emit a request to replace the current match.
replace_text() -> str
#
Return the current replacement text.
search_options() -> dict[str, bool]
#
Return the current search options.
search_text() -> str
#
Return the current search text.
set_match_count(total: int, current: int | None = None) -> None
#
Update the visible search status.
set_replace_text(text: str) -> None
#
Set the replacement text.
set_replace_visible(visible: bool) -> None
#
Show or hide the replace controls.
set_search_text(text: str) -> None
#
Set the search text.
set_target_editor(editor: TextEditor | None) -> None
#
Attach a text editor and drive search state from its content.