ZInputBox¶
ZInputBox is a single line text input widget. If the input text is longer than the width of the widget it supports scrolling the text so the currently edited portion of the text is visible.
Example¶
Tui::ZInputBox *inputbox = new Tui::ZInputBox("InputBox", dialog);
layout->addWidget(inputbox);
QObject::connect(inputbox, &Tui::ZInputBox::textChanged, [](const QString &text) { /* ... */ });
Keyboard Usage¶
Key |
Result |
---|---|
(text input) |
Insert text at cursor position. |
Backspace |
Remove one letter/character before cursor position. |
Del |
Remove one letter/character after cursor position. |
← |
Move cursor position one letter/character to the left. |
→ |
Move cursor position one letter/character to the right. |
Home |
Move cursor position to the start of the text. |
End |
Move cursor position to the position just after the end of the text. |
Insert |
Toggle overwrite mode. |
Behavior¶
Input boxes by default accept focus, are one cell high and have a expanding vertical layout policy. The size request of a checkbox is fixed at 10 cells width to avoid the layout changing when text is entered.
The user can edit the text by using the keys described in the keyboard usage section.
Additionally the input box accepts text pasted into the terminal and inserts it at the cursor position.
On each change to the text the input box
emits a textChanged(const QString &text)
signal.
When unfocused the text is always scrolled such that the start of the text is visible. When focused the text is scrolled so that the cursor position is visible.
Newline (\n
) characters in the text are displayed as in the following example (displaying one\ntwo
):
Other non printable characters are displayed using similar visual conventions.
Palette¶
Palette Color |
Usage |
---|---|
|
Body of the input box (active, unfocused) |
|
Body of the input box (active, focused) |
|
Body of the input box (disabled) |
ZInputBox¶
-
class Tui::ZInputBox : public Tui::ZWidget¶
A single line text input widget.
Enums
-
enum EchoMode¶
-
enumerator Normal¶
Display text normally
-
enumerator NoEcho¶
Do not display any text and show cursor at start of the widget. This is the classic everything hidden password input.
-
enumerator Password¶
Display text masked by
*
. This is the modern masked password input that leaks passwort length but provides better feedback and editing.
-
enumerator Normal¶
Constructors
-
ZInputBox(const QString &text, Tui::ZWidget *parent = nullptr)¶
Create the input box with the given
text
.
Functions
-
Tui::ZInputBox::EchoMode echoMode() const¶
The
echoMode
allows selecting how the input text is displayed. This allows selecting normal display or password input modes.
-
void setOverwriteMode(bool overwriteMode)¶
-
bool overwriteMode() const¶
The
overwriteMode
allows for user input to overwrite existing text.If true user input letters will overwrite the existing letter the cursor is placed on. Otherwise it will be inserted after the cursor.
-
int cursorPosition() const¶
-
void setCursorPosition(int pos)¶
The cursor position in code units.
If the cursor position is out of range it will be adjusted to be in the range from 0 to the length of the current text (in code units). The cursor position is conceptually between letters/characters (clusters).
If the given cursor position is not at the start of a cluster (or at the end of the text) in text, it will be adjusted to the preceding valid cursor position.
-
void insertAtCursorPosition(const QString &text)¶
Insert the text given in
text
at the current cursor position and emitstextChanged(const QString &text)
.
Signals
-
void textChanged(const QString &text)¶
This signal is emitted when the user changes the text or the text is changed using functions on this widget.
Slots
-
void setText(const QString &text)¶
If
text
differs from the current text: Replace the text withtext
and emitstextChanged(const QString &text)
. Sets cursor position to the end of the text.
-
enum EchoMode¶