Skip to content

Instantly share code, notes, and snippets.

@JanisErdmanis
Created March 16, 2023 16:24
Show Gist options
  • Save JanisErdmanis/4975e98a379d4bf325f265fc78f0cd80 to your computer and use it in GitHub Desktop.
Save JanisErdmanis/4975e98a379d4bf325f265fc78f0cd80 to your computer and use it in GitHub Desktop.
Example of dynamic survey and bridging that with julia while preserving ability to test UI with dummy data
ENV["QT_QUICK_CONTROLS_STYLE"] = "Basic"
using QML
mutable struct Question
title::String
options::Vector{String}
end
Question(title) = Question(title, ["1", "2", "3"])
bridge = QML.JuliaPropertyMap()
ballot = JuliaItemModel([Question("First"), Question("Second")])
loadqml("Survey.qml"; bridge = JuliaPropertyMap("ballot" => ballot))
exec()
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import org.julialang
Window {
id : window
width: 400
height: 700
visible: true
color: "#C1BCB5"
title: "Test"
//property var ballot : bridge.ballot
property var ballot : ListModel {
ListElement {
title : "First"
options : [
ListElement { item : "Skip"},
ListElement { item : "Yes"},
ListElement { item : "No"}
]
}
ListElement {
title : "Second"
options : [
ListElement { item : "1"},
ListElement { item : "2"},
ListElement { item : "3"}
]
}
}
ListView {
id : listview
anchors.fill : parent
anchors.topMargin : 50
spacing : 10
model : ballot
delegate : Item {
width : listview.width
height : 80
Text {
anchors.left : parent.left
anchors.topMargin : 10
font.pointSize : 16
text : title // model.title also works
}
ComboBox {
anchors.bottom : parent.bottom
anchors.bottomMargin : 10
width: parent.width
model : options // model.options DOES NOT WORK!!!
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment