DATextEditWidget¶
DATextEditWidget is a general-purpose text viewer/editor: it can toggle read-only, monospace, and line wrap, while toolbar actions are injected by the caller. It does not own OK / Cancel; wrap it in a QDialog when modal interaction is needed.
Preview¶

The toolbar in the screenshot contains only the "Save As" action injected by the demo; the widget only displays it and forwards triggered. The four checkboxes below toggle read-only, monospace, line wrap, and toolbar visibility. Monospace keeps columns aligned, which suits logs and config snippets.
Key Features¶
- ✅ Read-only / editable toggle:
setReadOnly() - ✅ Monospace:
setMonospace(), ideal for logs and code - ✅ Line wrap:
setLineWrapEnabled() - ✅ Injectable tool actions:
addToolAction(QAction*); the caller owns their lifetime - ✅ Line numbers (optional): a left gutter, off by default
- ✅ Find bar (optional):
Ctrl+F, wrap-around navigation and all-match highlighting, off by default - ✅ No business logic: no built-in save/close behavior, easy to reuse in dialogs or dock panels
Usage¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
setText does not emit textChanged
setText() is for programmatic writes and does not emit textChanged; only user edits emit it, avoiding feedback loops in the caller.
Line Numbers¶
1 | |
- Numbers are painted in a left gutter, follow scrolling, and the gutter width is recomputed from the total line count (also after
setMonospace()changes the font). - Line number = document block number: with line wrap enabled, a logical line folded into several visual rows still shows one number.
- When disabled,
viewportMarginsreturns to zero and the gutter takes no width.
Find Bar¶
1 2 3 | |
- After
setFindEnabled(true), pressingCtrl+Fwhile focus is inside the widget opens the find bar;Esccloses it and returns focus to the editor. - The bar contains an input, previous/next, an
n / mcounter, a match-case checkbox and a close button. All matches are highlighted; the current one is darker. - Wrap-around is supported: next after the last match returns to the first; with
m == 0the counter shows0 / 0and the input gets theinvaliddynamic property. - Works in read-only mode too (it only moves the cursor and highlights, never edits text).
- If the host also uses
Ctrl+F, callsetFindEnabled(false)to yield the shortcut. - Line numbers and find are pure view state and add no signals;
textChanged()still fires only for user edits.
Core Properties & Methods¶
| Method | Description |
|---|---|
setReadOnly(bool) / isReadOnly() |
Read-only state |
setMonospace(bool) / isMonospace() |
Monospace font |
setLineWrapEnabled(bool) / isLineWrapEnabled() |
Line wrap |
setText(QString) / text() |
Set/get text (setText emits no signal) |
setPlaceholderText(QString) |
Empty-state placeholder |
addToolAction(QAction*) |
Inject an action into the toolbar |
setToolbarVisible(bool) / isToolbarVisible() |
Toolbar visibility |
setLineNumbersVisible(bool) / lineNumbersVisible() |
Left line-number gutter (default off) |
setFindEnabled(bool) / findEnabled() |
Allow Ctrl+F (default off) |
setFindBarVisible(bool) / findBarVisible() |
Find bar visibility |
showFindBar(QString) / hideFindBar() |
Open (optionally prefilled) / close the find bar |
setFindCaseSensitive(bool) / findCaseSensitive() |
Whether find is case-sensitive |
References¶
- DAUndoHistoryWidget
- Example path:
examples/all_widgets_demo(Text tab)