Qt Widgets (Fusion)¶
The qt pack imitates desktop applications built with Qt 6 Widgets (C++, PySide6 or PyQt6)
in Qt's cross-platform Fusion style with its default palette: Window #efefef, Base #ffffff,
AlternateBase #f7f7f7, Highlight #308cc6, and in dark mode (Qt 6.5+ colour scheme) Window
#323232, Base #242424, Text #f0f0f0. Controls have Fusion's faint vertical gradient, a 1 px
outline and 2 px corners; item views are square framed panels with Highlight selection; the type is
the desktop's 9 pt UI font ("Segoe UI", "Noto Sans", "DejaVu Sans" …, 12 px).
Select it with import QtWidgets (also Qt, Qt6, PySide, PyQt) or pack="qt". Elements
use the Qt class names without the Q: MainWindow, MenuBar / Menu / Action / Separator,
ToolBar / ToolButton, StatusBar, DockWidget, GroupBox, TabWidget, Splitter,
PushButton, CheckBox, RadioButton, ComboBox, LineEdit, TextEdit, SpinBox, DateEdit,
CalendarWidget, Slider, Dial, ProgressBar, LCDNumber, ListWidget, TreeWidget +
HeaderView, TableView, MessageBox, FileDialog, DialogButtonBox, FormLayout + FormRow,
ToolBox, Wizard / WizardPage, ChartView and more — mockitdown elements qt lists them all.
Arguments follow the Qt properties (placeholderText:, currentText:, echoMode: .password,
checkState:, toolButtonStyle:, alternatingRowColors:, calendarPopup: …), and icons accept
freedesktop theme names ("document-save", "edit-copy") and QStyle standard pixmaps
("SP_DialogOkButton"). The reusable pieces below come from
mockups/qt/widgets.mockitdown.
Widgets gallery¶
Qt's own Widgets Gallery example in Fusion: radio buttons and a tri-state check box, the push button variants (default, toggle, flat), a tool button with a menu, a command link, a tab widget with a table, a checkable group of simple input widgets, and a progress bar.
| Name | Qty | Price |
|---|---|---|
| Apples | 12 | 1.20 |
| Pears | 4 | 0.95 |
| Plums | 30 | 0.40 |
| Figs | 7 | 2.10 |
| Kiwis | 18 | 0.55 |
| Name | Qty | Price |
|---|---|---|
| Apples | 12 | 1.20 |
| Pears | 4 | 0.95 |
| Plums | 30 | 0.40 |
| Figs | 7 | 2.10 |
| Kiwis | 18 | 0.55 |
Source
import QtWidgets
VBoxLayout(spacing: 8) {
HBoxLayout(spacing: 8) {
Label("Style:")
ComboBox(items: ["Fusion", "Windows"], currentText: "Fusion").frame(width: 120)
Label("Color scheme:")
ComboBox(items: ["Auto", "Light", "Dark"], currentText: "Auto").frame(width: 100)
Spacer()
CheckBox("Use style's standard palette", checked: true)
CheckBox("Disable widgets")
}
GridLayout(columns: 2, spacing: 8) {
GroupBox("Group 1") {
RadioButton("Radio button 1", checked: true)
RadioButton("Radio button 2")
RadioButton("Radio button 3")
CheckBox("Tri-state check box", checked: .indeterminate)
}
GroupBox("Group 2") {
PushButton("Default Push Button", default: true)
PushButton("Toggle Push Button", checked: true)
PushButton("Flat Push Button").flat()
HBoxLayout { ToolButton("Tool Button", popupMode: .menuButtonPopup); Spacer() }
CommandLinkButton("Command Link Button")
}
TabWidget(selection: "Table") {
Tab("Table") {
TableWidget(columns: ["Name", "Qty", "Price"],
rows: [["Apples", 12, "1.20"], ["Pears", 4, "0.95"], ["Plums", 30, "0.40"], ["Figs", 7, "2.10"], ["Kiwis", 18, "0.55"]],
selection: [1])
}
Tab("Text Edit") { TextEdit("Twinkle, twinkle, little star") }
Tab("Tree View") { TreeWidget { TreeWidgetItem("Item") } }
}
GroupBox("Group 3", checkable: true, checked: true) {
LineEdit("s3cRe7", echoMode: .password).state(.focused)
SpinBox(value: 50)
DateTimeEdit(dateTime: "2026-11-24 09:41")
HBoxLayout(spacing: 12) {
VBoxLayout(spacing: 10) {
Slider(value: 40, maximum: 100)
ScrollBar(value: 60, maximum: 100)
}
.frame(maxWidth: .infinity)
Dial(value: 30, maximum: 100, notchesVisible: true)
}
}
}
ProgressBar(value: 64)
}
.padding(9)Document editor¶
A classic MainWindow: a menu bar with the Edit menu open (icons, shortcuts, a disabled
action, a checkable action and a submenu), a tool bar of ToolButtons with a font combo box, a
document-mode TabWidget with closable tabs around the central TextEdit, two stacked
DockWidgets and a
StatusBar with permanent widgets on the right.
## New features
### Dark colour scheme
The editor now follows the system colour scheme (Qt 6.5 or later). Choose
View ▸ Appearance to force light or dark.
### Tabbed documents
Open several files in one window; drag a tab out to make a new window.
## New features
### Dark colour scheme
The editor now follows the system colour scheme (Qt 6.5 or later). Choose
View ▸ Appearance to force light or dark.
### Tabbed documents
Open several files in one window; drag a tab out to make a new window.
Preferences¶
A preferences window: a TabWidget whose pages hold GroupBoxes, right-aligned FormLayout
labels, a checkable group box, a KeySequenceEdit and the DialogButtonBox with the default
OK button.
Source
import QtWidgets
VBoxLayout(spacing: 9) {
TabWidget(selection: "Editor") {
Tab("General") { Label("") }
Tab("Editor") {
GroupBox("Font") {
FormLayout {
FormRow("Family:") { FontComboBox(currentText: "DejaVu Sans Mono") }
FormRow("Size:") { SpinBox(value: 11, suffix: " pt").frame(width: 90) }
FormRow("Line spacing:") { DoubleSpinBox(value: 1.25).frame(width: 90) }
}
}
GroupBox("Behavior") {
FormLayout {
FormRow("Tab policy:") { ComboBox(items: ["Spaces only", "Tabs only"], currentText: "Spaces only") }
FormRow("Tab size:") { SpinBox(value: 4).frame(width: 90) }
FormRow("Auto-save every:") { SpinBox(value: 5, suffix: " min").frame(width: 90) }
FormRow("Complete shortcut:") { KeySequenceEdit(keySequence: "Ctrl+Space") }
FormRow("") { CheckBox("Highlight current line", checked: true) }
FormRow("") { CheckBox("Wrap long lines") }
}
}
GroupBox("Spell checking", checkable: true, checked: false) {
FormLayout {
FormRow("Language:") { ComboBox(items: ["English (US)"], currentText: "English (US)") }
}
}
}
Tab("Appearance") { Label("") }
Tab("Shortcuts") { Label("") }
}
.frame(maxHeight: .infinity)
DialogButtonBox {
PushButton("Restore Defaults")
Spacer()
PushButton("OK", default: true)
PushButton("Cancel")
PushButton("Apply").disabled()
}
}
.padding(9)Data entry¶
An appointment form: a CalendarWidget (weekends in red, Highlight navigation bar) beside a
FormLayout with an editable ComboBox, TimeEdit, SpinBox with a suffix, a DateEdit with a
calendar popup, radio buttons in a horizontal layout and a PlainTextEdit.
Data browser¶
A database browser: a filter LineEdit, a column ComboBox and a checked tool button showing its
ToolTip in the tool bar, a Splitter
with a connection TreeWidget (with its HeaderView) on the left and a sorted TableView with
alternating rows, row numbers and a selected row on the right.
| TrackId | Name | Album | Composer | Genre | Milliseconds | UnitPrice |
|---|---|---|---|---|---|---|
| 1 | For Those About To Rock | For Those About To Rock | Angus Young, Malcolm Young | Rock | 343719 | 0.99 |
| 6 | Put The Finger On You | For Those About To Rock | Angus Young, Malcolm Young | Rock | 205662 | 0.99 |
| 7 | Let's Get It Up | For Those About To Rock | Angus Young, Malcolm Young | Rock | 233926 | 0.99 |
| 15 | Go Down | Let There Be Rock | AC/DC | Rock | 331180 | 0.99 |
| 16 | Dog Eat Dog | Let There Be Rock | AC/DC | Rock | 215196 | 0.99 |
| 17 | Let There Be Rock | Let There Be Rock | AC/DC | Rock | 366654 | 0.99 |
| 18 | Bad Boy Boogie | Let There Be Rock | AC/DC | Rock | 267728 | 0.99 |
| 19 | Problem Child | Let There Be Rock | AC/DC | Rock | 325041 | 0.99 |
| 20 | Overdose | Let There Be Rock | AC/DC | Rock | 369319 | 0.99 |
| 21 | Hell Ain't A Bad Place To Be | Let There Be Rock | AC/DC | Rock | 254380 | 0.99 |
| 22 | Whole Lotta Rosie | Let There Be Rock | AC/DC | Rock | 323761 | 0.99 |
| 23 | Walk On Water | Big Ones | Steven Tyler, Joe Perry | Rock | 295680 | 0.99 |
| 24 | Love In An Elevator | Big Ones | Steven Tyler, Joe Perry | Rock | 321828 | 0.99 |
| 25 | Rag Doll | Big Ones | Steven Tyler, Joe Perry | Rock | 264698 | 0.99 |
| 26 | What It Takes | Big Ones | Steven Tyler, Joe Perry | Rock | 310622 | 0.99 |
| 27 | Dude (Looks Like A Lady) | Big Ones | Steven Tyler, Joe Perry | Rock | 264855 | 0.99 |
Unsaved changes¶
A MessageBox with the standard warning icon, its text, the informative text and the
Save / Discard / Cancel buttons (Save is the default button). Qt dialogs are separate windows: they
do not dim their parent.
- oat milk
- lemons
- basil
Source
import QtWidgets
MainWindow {
MenuBar { Menu("File"); Menu("Edit"); Menu("View"); Menu("Help") }
CentralWidget {
PlainTextEdit(plainText: "Groceries\n- oat milk\n- lemons\n- basil").frame(maxHeight: .infinity)
}
StatusBar { Label("Modified") }
}
MessageBox("Text Editor", text: "The document has been modified.", icon: .warning,
buttons: ["Save", "Discard", "Cancel"], primary: "Save") {
Label("Do you want to save your changes?")
}Qt Designer¶
A Designer-like layout: the Widget Box as a ToolBox of categories with a filter, the form
being edited on Designer's dotted grid with a RubberBand selection, the Object Inspector
(TreeWidget with Object / Class columns) and the Property Editor — a property grid built from
the custom PropertyClass and Property components, with Designer's tinted class bands and bold
modified properties.
Bench monitor¶
An instrument panel: LCDNumber read-outs (the custom Readout component, used four times),
Dials with notches, a Qt Charts ChartView line chart and bar chart in the Qt Charts light /
dark themes, Sliders with tick marks and DoubleSpinBoxes for the set points.
Walkthrough: exporting a table¶
Qt's own (non-native) FileDialog, shown here as its own window. Pick the folder in the
Look in combo box 1 or the places side bar 2, select an existing file in the detail view
3 to reuse its name, type the File name 4 and choose the format in Files of type 5.
Save 6 is the default button, so Enter confirms.
Source
import QtWidgets
import "qt/widgets"
FileDialog("Export Table as CSV", inline: true) {
HBoxLayout(spacing: 4) {
Label("Look in:")
ComboBox(items: ["/home/brian/Documents/exports"], currentText: "/home/brian/Documents/exports")
.frame(maxWidth: .infinity)
.callout(1, alignment: .top)
ToolAction(icon: "go-previous"); ToolAction(icon: "go-next"); ToolAction(icon: "go-up")
ToolAction(icon: "folder-new"); ToolAction(icon: "view-list-icons")
ToolAction(icon: "view-list-details", checked: true)
}
Splitter {
FileDialogSidebar(selection: "Documents")
.frame(width: 130)
.callout(2, alignment: .bottomLeading)
TreeWidget {
HeaderView(["Name", "Size", "Type", "Date Modified"])
TreeWidgetItem("archive", icon: "folder") { Text(""); Text("Folder"); Text("11/02/26") }
TreeWidgetItem("albums.csv", icon: "text-x-generic") { Text("21 KB"); Text("csv File"); Text("11/20/26") }
TreeWidgetItem("tracks.csv", icon: "text-x-generic") { Text("312 KB"); Text("csv File"); Text("11/23/26") }
.selected()
TreeWidgetItem("invoices.csv", icon: "text-x-generic") { Text("88 KB"); Text("csv File"); Text("11/24/26") }
}
.frame(maxWidth: .infinity)
.callout(3, "Detail view", alignment: .center)
}
.frame(maxHeight: .infinity)
GridLayout(columns: [GridItem(.fixed(84)), GridItem(.flexible()), GridItem(.fixed(84))], spacing: 6) {
Label("File name:")
LineEdit("tracks.csv").state(.focused).callout(4, alignment: .trailing)
PushButton("Save", default: true).callout(6, alignment: .topTrailing)
Label("Files of type:")
ComboBox(items: ["CSV (*.csv *.tsv)"], currentText: "CSV (*.csv *.tsv)").callout(5, alignment: .trailing)
PushButton("Cancel")
}
}Custom components¶
The page imports qt/widgets from docs/mockups/qt/widgets.mockitdown. It defines ToolAction
(an icon-only tool-bar button), Property and PropertyClass (Designer's property grid),
Readout (an LCD instrument) and FileDialogSidebar (the places list of QFileDialog):
struct Readout: View {
var title: String
var value: String
var unit: String
var level: Double = 0.5
var segmentStyle: String = "filled"
var body: some View {
GroupBox(title) {
HBoxLayout(spacing: 6) {
LCDNumber(value, segmentStyle: segmentStyle).frame(maxWidth: .infinity)
Label(unit).frame(width: 34)
}
ProgressBar(value: level * 100, textVisible: false)
}
}
}