logoalt Hacker News

saidinesh5 • today at 6:31 AM • 1 reply • view on HN

I think Qt/QML really reached hit sweet spot for me when it comes to describing UIs (ignore if any syntax errors, doing this from memory):

For eg. compare this:

``` Window { textColor: "slategray" property int v: 40

    ColumnLayout {
        id: layout
        anchors.fill: parent
        spacing: 20

        Text {
            id: number
            Layout.alignment: Qt.AlignHCenter
            font.pixelSize: 70
            text: v
        }

        ProgressBar {
            id: progressBar
            Layout.alignment: Qt.AlignHCenter
  
            value: v/100
            color: v < 50 ? "dodgerblue" : "turquoise"
        }
    }

    MouseArea {
        anchors.fill: parent
        onClick: v = (v+20)%100
    }
} ```

with Declare:

``` App [ textColor = slategray,

    group: View [ x = center, y = center, width = 80%,
        layout: SimpleLayout [ axis = y, spacing = 20 ],

        number: Text [ width = 100%, textAlign = center,
            fontSize = 70, fontWeight = bold, text = { "" + v } ],

        bar: Gauge [ width = 100%, value = { v },
            tint = { v < 50 ? cool : warm }, accessibilityLabel = "v" ],

        hint: Text [ width = 100%, textAlign = center,
            text = "click anywhere to change v" ]
        ],

    v: number = 40,
    cool: Color = dodgerblue,
    warm: Color = turquoise,

    onClick() { v = (v + 20) % 100 }
    ]
```

Replies

pennomi • today at 2:05 PM

QML was really something special. I’m sad that type of syntax never really caught on in the wider UI world.