Your first log pane¶
The quick start shows the widget on its own. A real app puts it in a window next to a search box. This guide builds that window step by step: viewer, search field, match counter, and a filter that hides lines that don't match.
The window¶
AnsiTextViewer is a regular QWidget, so it goes into any layout:
This already runs. The next two steps add code to it; each listing's header says where the lines go.
Wire up search¶
highlight_search() highlights every match, jumps to the first one, and
returns the count. The counter also has to follow F3 and Shift+F3:
the viewer emits nextRequested / prevRequested just before it moves,
and wraps around at the ends, so the counter mirrors that.
Connect the signals at the end of __init__:
self.search.textChanged.connect(self.run_search)
self.viewer.findRequested.connect(self.focus_search)
self.viewer.nextRequested.connect(lambda: self.step(+1))
self.viewer.prevRequested.connect(lambda: self.step(-1))
Then add these methods to LogWindow:
def run_search(self, text):
self.total = self.viewer.highlight_search(text)
self.current = 1 if self.total else 0
self.update_count()
def step(self, delta):
# Runs just before the viewer moves; wrap the same way it does.
if self.total:
self.current = (self.current - 1 + delta) % self.total + 1
self.update_count()
def update_count(self):
self.count.setText(f"{self.current}/{self.total}")
def focus_search(self):
self.search.setFocus()
self.search.selectAll()
The shortcuts are built in: Ctrl+F emits findRequested, F3 and
Shift+F3 emit nextRequested / prevRequested and then move between
matches, and Esc clears the highlight. They are application-wide, so
F3 still works while the search box has focus.
Your own buttons
Buttons don't need the signals. Call the methods and use their return
values: next_match() and prev_match() return the 1-based index of
the match that is now active.
Wire up the filter¶
filter_search() hides every line that doesn't match. An empty query shows
everything again, and new lines are filtered as they arrive, so a live
stream respects the filter. One more line at the end of __init__:
Both highlight_search() and filter_search() accept use_regex=True and
match_case=True. Invalid regex falls back to a literal search instead of
raising, and patterns over 500 characters are rejected, so you can pass user
input straight through.
The whole file¶
log_window.py, assembled

timeout into the search box.Next steps¶
- Feed it real output: Streaming process output.
- Match your app's look: Themes and colors.
- Bookmarks, sessions, and export: Viewer API.