Skip to main content

QCustomVerificationCode

QCustomVerificationCode

A segmented one-time-code input.

The row of single-character boxes used for 2FA / OTP / email confirmation codes. Painted as one widget rather than assembled from N QLineEdits, so focus, paste and backspace behave as users expect instead of fighting Qt's per-field focus chain.

Behaviour that the naive N-QLineEdit version gets wrong and this does not:

  • pasting a whole code fills every box, however it is formatted
  • backspace on an empty box steps back and clears the previous one
  • arrow keys and Home/End move the caret without destroying input
  • only characters permitted by inputMode are accepted at all

Emits codeChanged(str) on every edit and completed(str) once the last box is filled.

At a glance

TierFree (GPLv3)
Importfrom Custom_Widgets.QCustomVerificationCode import QCustomVerificationCode
Qt DesignerYes — drag it from the palette

Quick start

from Custom_Widgets.QCustomVerificationCode import QCustomVerificationCode

widget = QCustomVerificationCode()

Dark theme

Colours come from the design tokens, so the widget follows the app theme with no extra work.

QCustomVerificationCode in dark theme

Properties

Every property below is settable in code and in Qt Designer.

PropertyTypeDefault
codestring
digitsint6
inputModeenum: numeric/alphanumeric/alpha``numeric
maskedboolFalse
uppercaseboolTrue
separatorAfterint0
boxWidthint40
boxHeightint48
boxSpacingint8
stateenum: default/error``default
boxBackgroundColorcolor
boxBorderColorcolor
boxBorderActiveColorcolor
boxBorderErrorColorcolor
textColorcolor

Signals

Signal
codeChanged(QString)
completed(QString)

Methods

MethodDescription
boxBackgroundColor(*args, **kwargs)Box background color.
boxBorderActiveColor(*args, **kwargs)Box border active color.
boxBorderColor(*args, **kwargs)Box border color.
boxBorderErrorColor(*args, **kwargs)Box border error color.
boxHeight(*args, **kwargs)Box height.
boxSpacing(*args, **kwargs)Box spacing.
boxWidth(*args, **kwargs)Box width.
clear()Clear.
code(*args, **kwargs)Code.
codeChanged(...)Code changed.
completed(...)Completed.
digits(*args, **kwargs)Digits.
inputMode(*args, **kwargs)Input mode.
isComplete()Return whether the widget is complete.
masked(*args, **kwargs)Masked.
pasteFromClipboard()Fill from the clipboard. Bound to Ctrl+V.
separatorAfter(*args, **kwargs)Separator after.
setCodeText(text)Fill from a string, ignoring anything the input mode disallows.
state(*args, **kwargs)State.
textColor(*args, **kwargs)Text color.
uppercase(*args, **kwargs)Uppercase.

Theming

Colours come from the design tokens, so they follow the active theme. Roles used: surface, on-surface, outline, focus-ring, destructive.

See Design tokens.

Runnable example

A complete app using this widget lives at examples/PySide6/QCustomVerificationCode/main.py.

QCustomButtonGroup · QCustomCheckBox · QCustomColorPicker · QCustomComboBox · QCustomDateEdit · QCustomDateRangePicker · QCustomEmojiPicker · QCustomFileDropZone