Elegant
Your First App
Write a QML file, check it from the command line, open it in a window with ljos run and update it live with --watch.
In this guide you will write a small QML application, check and format it from the command line, open it in a window with ljos run, and edit it while it runs with --watch.
Write a QML file
Create a new directory for your project and save the following file as Main.qml:
Main.qml
QML
Copy
import Ljos.Ui
import Ljos.Layout
import Ljos.Controls

Rectangle {
    id: root
    width: 300
    height: 200
    fill: palette.base

    property int count: 0

    Column {
        anchors.centerIn: parent
        spacing: 12

        Text {
            id: label
            color: palette.text
            text: "Count: " + root.count
            font.size: 20
            align: Text.AlignHCenter
        }

        Button {
            id: bumpButton
            text: "Increment"
            onClicked: root.count += 1
        }
    }
}
Edit
Source
What this example draws
What this example draws
Check and format the file
Before opening a window, run ljos check on the directory to verify that your QML compiles cleanly and passes the accessibility and design lints:
Shell
Copy
ljos check .
Text
Copy
1 files, 0 errors, 0 warnings
You can also format the file in place using ljos fmt:
Shell
Copy
ljos fmt Main.qml
ljos fmt lays out QML files with one member per line and four spaces per indentation level while keeping your comments and JavaScript expressions intact.
Run the application
Open Main.qml in a window with ljos run:
Shell
Copy
ljos run Main.qml
Without --size, ljos run opens the window at the root item's own width and height (300 by 200 logical pixels here). If a root item leaves a dimension at 0, that side defaults to 800 by 600. You can override the window size from the command line with --size:
Shell
Copy
ljos run --size 400x300 Main.qml
Click the Increment button a few times. Each click updates root.count, and the Text binding updates "Count: " + root.count immediately.
Edit live with --watch
Stop the previous run and start ljos run again with --watch:
Shell
Copy
ljos run --watch Main.qml
Click Increment until the counter reads Count: 3. Leave the window open, then edit Main.qml in your editor to change the background colour, the heading text and add a second button:
Main.qml
QML
Copy
import Ljos.Ui
import Ljos.Layout
import Ljos.Controls

Rectangle {
    id: root
    width: 300
    height: 200
    fill: palette.button

    property int count: 0

    Column {
        anchors.centerIn: parent
        spacing: 12

        Text {
            id: label
            color: palette.buttonText
            text: "Total clicks: " + root.count
            font.size: 20
            font.weight: Font.Bold
            align: Text.AlignHCenter
        }

        Button {
            id: bumpButton
            text: "Increment"
            onClicked: root.count += 1
        }

        Button {
            id: resetButton
            text: "Reset"
            onClicked: root.count = 0
        }
    }
}
Edit
Source
What this example draws
What this example draws
As soon as you save Main.qml:
The window stays open and changes its background from palette.base to palette.button.
root.count keeps its value (3), because it was assigned by a script handler (onClicked: root.count += 1) and root is matched across the reload by its id.
label.text re-evaluates its new binding and shows "Total clicks: 3" in bold.
The new Reset button appears below Increment.
If you make a syntax mistake while editing and save the file, the running application stays alive and shows an error banner with the file, line and column. When you fix the mistake and save again, the banner clears and the new QML applies in place.
Render a picture without a window
You can also draw the project to a PNG image headlessly with ljos render:
Shell
Copy
ljos render . --out preview.png --settle 0
This renders Main.qml using the bundled font for deterministic output and writes preview.png at 300 by 200 pixels.
See also
Your First App
Write a QML file, check it from the command line, open it in a window with ljos run and update it live with --watch.
In this guide you will write a small QML application, check and format it from the command line, open it in a window with ljos run, and edit it while it runs with --watch.
Write a QML file
Create a new directory for your project and save the following file as Main.qml:
Main.qml
QML
Copy
What this example draws
What this example draws
Edit
Source
import Ljos.Ui
import Ljos.Layout
import Ljos.Controls

Rectangle {
    id: root
    width: 300
    height: 200
    fill: palette.base

    property int count: 0

    Column {
        anchors.centerIn: parent
        spacing: 12

        Text {
            id: label
            color: palette.text
            text: "Count: " + root.count
            font.size: 20
            align: Text.AlignHCenter
        }

        Button {
            id: bumpButton
            text: "Increment"
            onClicked: root.count += 1
        }
    }
}
Show all 31 lines
Check and format the file
Before opening a window, run ljos check on the directory to verify that your QML compiles cleanly and passes the accessibility and design lints:
Shell
Copy
ljos check .
Text
Copy
1 files, 0 errors, 0 warnings
You can also format the file in place using ljos fmt:
Shell
Copy
ljos fmt Main.qml
ljos fmt lays out QML files with one member per line and four spaces per indentation level while keeping your comments and JavaScript expressions intact.
Run the application
Open Main.qml in a window with ljos run:
Shell
Copy
ljos run Main.qml
Without --size, ljos run opens the window at the root item's own width and height (300 by 200 logical pixels here). If a root item leaves a dimension at 0, that side defaults to 800 by 600. You can override the window size from the command line with --size:
Shell
Copy
ljos run --size 400x300 Main.qml
Click the Increment button a few times. Each click updates root.count, and the Text binding updates "Count: " + root.count immediately.
Edit live with --watch
Stop the previous run and start ljos run again with --watch:
Shell
Copy
ljos run --watch Main.qml
Click Increment until the counter reads Count: 3. Leave the window open, then edit Main.qml in your editor to change the background colour, the heading text and add a second button:
Main.qml
QML
Copy
What this example draws
What this example draws
Edit
Source
import Ljos.Ui
import Ljos.Layout
import Ljos.Controls

Rectangle {
    id: root
    width: 300
    height: 200
    fill: palette.button

    property int count: 0

    Column {
        anchors.centerIn: parent
        spacing: 12

        Text {
            id: label
            color: palette.buttonText
            text: "Total clicks: " + root.count
            font.size: 20
            font.weight: Font.Bold
            align: Text.AlignHCenter
        }

        Button {
            id: bumpButton
            text: "Increment"
            onClicked: root.count += 1
        }

        Button {
            id: resetButton
            text: "Reset"
            onClicked: root.count = 0
        }
    }
}
Show all 38 lines
As soon as you save Main.qml:
The window stays open and changes its background from palette.base to palette.button.
root.count keeps its value (3), because it was assigned by a script handler (onClicked: root.count += 1) and root is matched across the reload by its id.
label.text re-evaluates its new binding and shows "Total clicks: 3" in bold.
The new Reset button appears below Increment.
If you make a syntax mistake while editing and save the file, the running application stays alive and shows an error banner with the file, line and column. When you fix the mistake and save again, the banner clears and the new QML applies in place.
Render a picture without a window
You can also draw the project to a PNG image headlessly with ljos render:
Shell
Copy
ljos render . --out preview.png --settle 0
This renders Main.qml using the bundled font for deterministic output and writes preview.png at 300 by 200 pixels.
See also