Skip to content

QML Cheatsheet

Syntax Basics

Property Declarations

qml
property int count: 0
property string name: "hello"
property color bgColor: "#1e1e2e"
property var anything: [1, "two", true]
readonly property double pi: 3.14159
required property string modelData

Property Bindings

qml
// Automatic binding
Rectangle { width: parent.width * 0.5; height: width * 0.75 }

// Imperative binding (preserve after JS assignment)
height = Qt.binding(function() { return width * 0.75 })

Signal Handlers

qml
onClicked: console.log("clicked")
onTextChanged: function(newText) { search(newText) }

// Custom signal
signal activated(string item)
onActivated: function(item) { console.log(item) }

Functions

qml
function add(a, b) { return a + b }

Import Types

qml
import Quickshell                                                 // Core types
import Quickshell.Services.Hardware                               // CPU, Memory
import "util/format.js" as Format                                  // JS library
import "Theme.qml" as Theme                                       // Singleton
import qs.widgets                                                  // Module (v0.2.0+)

Quickshell Types Quick Reference

TypeImportUse
PanelWindowQuickshellMain bar/panel attached to screen edge
PopupWindowQuickshellPopup relative to a parent window
FloatingWindowQuickshellStandard desktop window
ShellRootQuickshellRoot element of every config
VariantsQuickshellCreate one delegate per model item
ScopeQuickshellCreate a child scope
SingletonQuickshellSingleton type reference
QuickshellQuickshellGlobal singleton with paths, screens
SystemClockQuickshellTime service

Common QML Components

TypeImportUse
ItemQtQuickInvisible container
RectangleQtQuickColored rectangle
TextQtQuickText label
ImageQtQuickImage display
MouseAreaQtQuickMouse click/hover events
ListViewQtQuickScrollable list
GridQtQuickGrid layout
RowQtQuickHorizontal layout
ColumnQtQuickVertical layout
TimerQtQuickDelayed/repeated execution
LoaderQtQuickDynamic component loading
ConnectionsQtQuickConnect to signals from another object
BindingQtQmlCreate imperative binding
ListModelQtQmlData model for ListView

Built-in Services

ServiceImportKey Properties
CpuServiceQuickshell.Services.HardwareusagePercent
MemoryServiceQuickshell.Services.HardwareusedPercent, totalKB, availableKB
BatteryServiceQuickshell.Services.Hardwarepercent, charging, state
SystemClockQuickshelldate, precision
MprisServiceQuickshell.Services.Mprisplayers, title, artist

Useful Qt Functions

qml
Qt.formatDateTime(date, "hh:mm AP")     // Format dates
Qt.binding(function() { return ... })    // Create binding
Qt.quit()                                // Exit the application
Qt.open(path, mode)                      // Open file for reading/writing
Qt.process(array)                        // Run command (async)
Qt.execDetached(object)                  // Run command (detached)
Qt.dbusCall(bus, path, iface, method)    // D-Bus method call

CSS-like Colors

qml
color: "#1e1e2e"            // Hex
color: Qt.rgba(0.1, 0.1, 0.2, 1.0)  // RGBA
color: Qt.lighter(color, 1.2)        // Brighten by 20%
color: Qt.darker(color, 1.2)         // Darken by 20%
color: Qt.tint(color, Qt.rgba(1, 0, 0, 0.2))  // Tint with red
color: "transparent"         // Fully transparent
What You've Learned
  • QML property declarations use property type name: value syntax
  • Import qs.module for directory-wide imports (v0.2.0+)
  • PanelWindow needs at least 2 opposite anchors
  • Use Qt.process([...]) for async commands, Qt.execDetached() for fire-and-forget

Built with VitePress. Licensed under MIT.