Skip to content

Instantly share code, notes, and snippets.

@M4rtinK
Created December 25, 2014 16:21
Show Gist options
  • Save M4rtinK/5eac64011483fb2aef8a to your computer and use it in GitHub Desktop.
Save M4rtinK/5eac64011483fb2aef8a to your computer and use it in GitHub Desktop.
Filling a Silica ComboBox from PyOtherSide - approximate untested example
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.0
ComboBox {
width: 480
label: "Foo Bar"
id: fooBox
property var dataModel : ListModel {}
Python {
id: py
Component.onCompleted: {
// Add the directory of this .qml file to the search path
addImportPath(Qt.resolvedUrl('.'));
// Import the main module and load the data
importModule('listmodel', function () {
py.call('listmodel.get_data', [], function(result) {
// Load the received data into the list model
for (var i=0; i<result.length; i++) {
dataModel.append(result[i]);
}
});
});
}
}
menu: ContextMenu {
Repeater {
model: fooBox.dataModel
MenuItem {
text: "Item #" + model.index
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment