or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

buttons.mddialog-notification.mddisplay-widgets.mdindex.mdinput-controls.mdlayout-animation.mdlist-view-widgets.mdmaterial-effects.mdmenu-command.mdmultimedia.mdsettings-config.mdtheme-styling.mdwindow-navigation.md

input-controls.mddocs/

0

# Input Controls

1

2

Comprehensive form controls including text inputs, combo boxes, sliders, date/time pickers, and spinboxes with fluent design styling and advanced features. All input controls provide consistent user interaction patterns, validation support, and automatic theme integration.

3

4

## Capabilities

5

6

### Text Input Controls

7

8

Single and multi-line text input widgets with modern styling and specialized variants for different input types.

9

10

```python { .api }

11

class LineEdit(QLineEdit):

12

def __init__(self, parent=None): ...

13

def setPlaceholderText(self, text: str): ...

14

def placeholderText(self) -> str: ...

15

16

class SearchLineEdit(LineEdit):

17

def __init__(self, parent=None): ...

18

def setSearchButtonVisible(self, visible: bool): ...

19

searchSignal = pyqtSignal(str)

20

clearSignal = pyqtSignal()

21

22

class PasswordLineEdit(LineEdit):

23

def __init__(self, parent=None): ...

24

def setEchoMode(self, mode: QLineEdit.EchoMode): ...

25

26

class TextEdit(QTextEdit):

27

def __init__(self, parent=None): ...

28

def setPlaceholderText(self, text: str): ...

29

30

class PlainTextEdit(QPlainTextEdit):

31

def __init__(self, parent=None): ...

32

def setPlaceholderText(self, text: str): ...

33

34

class TextBrowser(QTextBrowser):

35

def __init__(self, parent=None): ...

36

```

37

38

**Usage Example:**

39

```python

40

from qfluentwidgets import (LineEdit, SearchLineEdit, PasswordLineEdit,

41

TextEdit, PlainTextEdit)

42

43

# Basic text input

44

name_input = LineEdit(self)

45

name_input.setPlaceholderText("Enter your name")

46

name_input.textChanged.connect(self.on_name_changed)

47

48

# Search input with search button

49

search_input = SearchLineEdit(self)

50

search_input.setPlaceholderText("Search files...")

51

search_input.searchSignal.connect(self.perform_search)

52

search_input.clearSignal.connect(self.clear_search)

53

54

# Password input

55

password_input = PasswordLineEdit(self)

56

password_input.setPlaceholderText("Password")

57

password_input.setEchoMode(QLineEdit.Password)

58

59

# Multi-line text

60

description_input = TextEdit(self)

61

description_input.setPlaceholderText("Enter description here...")

62

description_input.setMaximumHeight(120)

63

64

# Plain text editor

65

code_editor = PlainTextEdit(self)

66

code_editor.setPlaceholderText("Enter code here...")

67

font = QFont("Consolas", 10)

68

code_editor.setFont(font)

69

```

70

71

### Combo Box Controls

72

73

Dropdown selection controls with support for editable options, custom models, and various selection patterns.

74

75

```python { .api }

76

class ComboBox(QComboBox):

77

def __init__(self, parent=None): ...

78

def setPlaceholderText(self, text: str): ...

79

def addItems(self, items: List[str]): ...

80

def setCurrentIndex(self, index: int): ...

81

def setCurrentText(self, text: str): ...

82

83

class EditableComboBox(ComboBox):

84

def __init__(self, parent=None): ...

85

def setCompleter(self, completer: QCompleter): ...

86

87

class ModelComboBox(ComboBox):

88

def __init__(self, parent=None): ...

89

def setModel(self, model: QAbstractItemModel): ...

90

91

class EditableModelComboBox(ModelComboBox):

92

def __init__(self, parent=None): ...

93

```

94

95

**Usage Example:**

96

```python

97

from qfluentwidgets import ComboBox, EditableComboBox, ModelComboBox

98

from PyQt5.QtCore import QStringListModel

99

100

# Basic combo box

101

language_combo = ComboBox(self)

102

language_combo.setPlaceholderText("Select language")

103

languages = ["Python", "JavaScript", "Java", "C++", "C#"]

104

language_combo.addItems(languages)

105

language_combo.setCurrentIndex(-1) # No selection

106

language_combo.currentTextChanged.connect(self.on_language_changed)

107

108

# Editable combo box

109

country_combo = EditableComboBox(self)

110

countries = ["United States", "Canada", "United Kingdom", "Germany"]

111

country_combo.addItems(countries)

112

country_combo.setPlaceholderText("Type or select country")

113

114

# Model-based combo box

115

model = QStringListModel(["Item 1", "Item 2", "Item 3"])

116

model_combo = ModelComboBox(self)

117

model_combo.setModel(model)

118

model_combo.setPlaceholderText("Choose from model")

119

```

120

121

### Slider Controls

122

123

Interactive sliders for numeric value selection with smooth animations and custom styling.

124

125

```python { .api }

126

class Slider(QSlider):

127

def __init__(self, orientation=Qt.Horizontal, parent=None): ...

128

def setRange(self, min: int, max: int): ...

129

def setValue(self, value: int): ...

130

def value(self) -> int: ...

131

132

class ClickableSlider(Slider):

133

def __init__(self, orientation=Qt.Horizontal, parent=None): ...

134

# Allows clicking anywhere on slider to set value

135

136

class HollowHandleStyle:

137

# Custom slider handle style with hollow appearance

138

pass

139

```

140

141

**Usage Example:**

142

```python

143

from qfluentwidgets import Slider, ClickableSlider

144

from PyQt5.QtCore import Qt

145

146

# Horizontal slider

147

volume_slider = Slider(Qt.Horizontal, self)

148

volume_slider.setRange(0, 100)

149

volume_slider.setValue(50)

150

volume_slider.valueChanged.connect(self.set_volume)

151

152

# Vertical slider

153

brightness_slider = Slider(Qt.Vertical, self)

154

brightness_slider.setRange(0, 255)

155

brightness_slider.setValue(128)

156

157

# Clickable slider (jump to click position)

158

seek_slider = ClickableSlider(Qt.Horizontal, self)

159

seek_slider.setRange(0, 1000)

160

seek_slider.sliderPressed.connect(self.start_seeking)

161

seek_slider.sliderReleased.connect(self.stop_seeking)

162

```

163

164

### Spin Box Controls

165

166

Numeric input controls with increment/decrement buttons and validation.

167

168

```python { .api }

169

class SpinBox(QSpinBox):

170

def __init__(self, parent=None): ...

171

def setRange(self, min: int, max: int): ...

172

def setSingleStep(self, step: int): ...

173

174

class DoubleSpinBox(QDoubleSpinBox):

175

def __init__(self, parent=None): ...

176

def setRange(self, min: float, max: float): ...

177

def setDecimals(self, decimals: int): ...

178

179

class CompactSpinBox(SpinBox):

180

def __init__(self, parent=None): ...

181

# Smaller, more compact version

182

183

class CompactDoubleSpinBox(DoubleSpinBox):

184

def __init__(self, parent=None): ...

185

```

186

187

**Usage Example:**

188

```python

189

from qfluentwidgets import SpinBox, DoubleSpinBox, CompactSpinBox

190

191

# Integer spin box

192

quantity_spin = SpinBox(self)

193

quantity_spin.setRange(1, 100)

194

quantity_spin.setSingleStep(1)

195

quantity_spin.setValue(1)

196

quantity_spin.valueChanged.connect(self.update_quantity)

197

198

# Double precision spin box

199

price_spin = DoubleSpinBox(self)

200

price_spin.setRange(0.0, 999999.99)

201

price_spin.setDecimals(2)

202

price_spin.setSingleStep(0.01)

203

price_spin.setPrefix("$")

204

205

# Compact spin box for toolbars

206

compact_spin = CompactSpinBox(self)

207

compact_spin.setRange(1, 10)

208

compact_spin.setValue(5)

209

```

210

211

### Date and Time Controls

212

213

Date and time selection widgets with calendar popups and various display formats.

214

215

```python { .api }

216

class DateEdit(QDateEdit):

217

def __init__(self, parent=None): ...

218

def setDate(self, date: QDate): ...

219

def date(self) -> QDate: ...

220

221

class TimeEdit(QTimeEdit):

222

def __init__(self, parent=None): ...

223

def setTime(self, time: QTime): ...

224

def time(self) -> QTime: ...

225

226

class DateTimeEdit(QDateTimeEdit):

227

def __init__(self, parent=None): ...

228

def setDateTime(self, datetime: QDateTime): ...

229

def dateTime(self) -> QDateTime: ...

230

231

class CompactDateEdit(DateEdit): ...

232

class CompactTimeEdit(TimeEdit): ...

233

class CompactDateTimeEdit(DateTimeEdit): ...

234

```

235

236

**Usage Example:**

237

```python

238

from qfluentwidgets import DateEdit, TimeEdit, DateTimeEdit

239

from PyQt5.QtCore import QDate, QTime, QDateTime

240

241

# Date picker

242

birth_date = DateEdit(self)

243

birth_date.setDate(QDate.currentDate())

244

birth_date.setDisplayFormat("yyyy-MM-dd")

245

birth_date.dateChanged.connect(self.on_date_changed)

246

247

# Time picker

248

appointment_time = TimeEdit(self)

249

appointment_time.setTime(QTime.currentTime())

250

appointment_time.setDisplayFormat("hh:mm AP")

251

252

# Date and time picker

253

event_datetime = DateTimeEdit(self)

254

event_datetime.setDateTime(QDateTime.currentDateTime())

255

event_datetime.setDisplayFormat("yyyy-MM-dd hh:mm")

256

```

257

258

### Switch Controls

259

260

Toggle switches for boolean settings and on/off states.

261

262

```python { .api }

263

class SwitchButton(QWidget):

264

def __init__(self, parent=None, indicatorPos=IndicatorPosition.LEFT): ...

265

def setChecked(self, checked: bool): ...

266

def isChecked(self) -> bool: ...

267

def setText(self, text: str): ...

268

def text(self) -> str: ...

269

270

checkedChanged = pyqtSignal(bool)

271

272

class IndicatorPosition(Enum):

273

LEFT = 0

274

RIGHT = 1

275

```

276

277

**Usage Example:**

278

```python

279

from qfluentwidgets import SwitchButton, IndicatorPosition

280

281

# Basic switch

282

notifications_switch = SwitchButton(self)

283

notifications_switch.setText("Enable Notifications")

284

notifications_switch.setChecked(True)

285

notifications_switch.checkedChanged.connect(self.toggle_notifications)

286

287

# Switch with indicator on right

288

auto_save_switch = SwitchButton(self, IndicatorPosition.RIGHT)

289

auto_save_switch.setText("Auto Save")

290

auto_save_switch.setChecked(False)

291

292

# Multiple switches in settings

293

switches = [

294

("Dark Mode", self.toggle_dark_mode),

295

("Sound Effects", self.toggle_sound),

296

("Auto Updates", self.toggle_updates)

297

]

298

299

for text, callback in switches:

300

switch = SwitchButton(self)

301

switch.setText(text)

302

switch.checkedChanged.connect(callback)

303

```

304

305

### Check Box Controls

306

307

Enhanced check boxes with fluent design styling and tri-state support.

308

309

```python { .api }

310

class CheckBox(QCheckBox):

311

def __init__(self, parent=None): ...

312

def __init__(self, text: str, parent=None): ...

313

def setTristate(self, tristate: bool = True): ...

314

def isTristate(self) -> bool: ...

315

```

316

317

**Usage Example:**

318

```python

319

from qfluentwidgets import CheckBox

320

from PyQt5.QtCore import Qt

321

322

# Basic checkbox

323

agree_checkbox = CheckBox("I agree to the terms and conditions", self)

324

agree_checkbox.stateChanged.connect(self.on_agreement_changed)

325

326

# Tri-state checkbox for hierarchical selection

327

parent_checkbox = CheckBox("Select All", self)

328

parent_checkbox.setTristate(True)

329

parent_checkbox.stateChanged.connect(self.on_parent_selection_changed)

330

331

# Child checkboxes

332

child_checkboxes = []

333

for item in ["Item 1", "Item 2", "Item 3"]:

334

checkbox = CheckBox(item, self)

335

checkbox.stateChanged.connect(self.update_parent_state)

336

child_checkboxes.append(checkbox)

337

```

338

339

### Advanced Input Features

340

341

#### Line Edit with Buttons

342

```python { .api }

343

class LineEditButton(LineEdit):

344

def __init__(self, parent=None): ...

345

def addButton(self, button: QToolButton, position: QLineEdit.ActionPosition): ...

346

```

347

348

**Usage Example:**

349

```python

350

from qfluentwidgets import LineEditButton, FluentIcon as FIF

351

from PyQt5.QtWidgets import QToolButton

352

353

# Line edit with custom buttons

354

search_edit = LineEditButton(self)

355

search_edit.setPlaceholderText("Search...")

356

357

# Add search button

358

search_btn = QToolButton()

359

search_btn.setIcon(FIF.SEARCH.icon())

360

search_btn.clicked.connect(self.perform_search)

361

search_edit.addButton(search_btn, QLineEdit.TrailingPosition)

362

363

# Add clear button

364

clear_btn = QToolButton()

365

clear_btn.setIcon(FIF.CLOSE.icon())

366

clear_btn.clicked.connect(search_edit.clear)

367

search_edit.addButton(clear_btn, QLineEdit.TrailingPosition)

368

```

369

370

## Input Validation and Error Handling

371

372

### Built-in Validation

373

```python

374

# Numeric validation

375

spin_box = SpinBox(self)

376

spin_box.setRange(1, 100) # Automatically validates range

377

378

# Date validation

379

date_edit = DateEdit(self)

380

date_edit.setDateRange(QDate(2020, 1, 1), QDate(2030, 12, 31))

381

382

# Text length validation

383

line_edit = LineEdit(self)

384

line_edit.setMaxLength(50)

385

```

386

387

### Custom Validation

388

```python

389

from PyQt5.QtGui import QValidator

390

391

class EmailValidator(QValidator):

392

def validate(self, text: str, pos: int):

393

if "@" in text and "." in text.split("@")[-1]:

394

return QValidator.Acceptable, text, pos

395

return QValidator.Intermediate, text, pos

396

397

# Apply custom validator

398

email_edit = LineEdit(self)

399

email_edit.setValidator(EmailValidator())

400

```

401

402

### Input State Management

403

```python

404

# Track input changes

405

def setup_form_validation(self):

406

self.required_fields = [name_edit, email_edit, phone_edit]

407

408

for field in self.required_fields:

409

field.textChanged.connect(self.validate_form)

410

411

def validate_form(self):

412

all_valid = all(field.text().strip() for field in self.required_fields)

413

self.submit_button.setEnabled(all_valid)

414

```

415

416

## Accessibility and User Experience

417

418

### Keyboard Navigation

419

```python

420

# Set tab order for form controls

421

self.setTabOrder(name_edit, email_edit)

422

self.setTabOrder(email_edit, phone_edit)

423

self.setTabOrder(phone_edit, submit_button)

424

```

425

426

### Screen Reader Support

427

```python

428

# Set accessible names and descriptions

429

name_edit.setAccessibleName("Full Name")

430

email_edit.setAccessibleDescription("Enter your email address")

431

```

432

433

### Input Feedback

434

```python

435

# Visual feedback for validation

436

def on_email_validation(self, is_valid: bool):

437

if is_valid:

438

email_edit.setStyleSheet("border: 2px solid green;")

439

else:

440

email_edit.setStyleSheet("border: 2px solid red;")

441

```