Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Last active September 27, 2017 06:25
Show Gist options
  • Select an option

  • Save yamahigashi/eb5dee98071679c3031765106e3e38dc to your computer and use it in GitHub Desktop.

Select an option

Save yamahigashi/eb5dee98071679c3031765106e3e38dc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -'''- coding: utf-8 -'''-
import os
import sys
from PySide2 import QtQuickWidgets
from PySide2.QtCore import QUrl
class MainWindow(QtQuickWidgets.QQuickWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
p = r"D:/Qt/qml_test/test.qml"
self.setSource(QUrl.fromLocalFile(p))
if __name__ == '__main__':
window = MainWindow()
window.show()
print(window.errors())
import QtQuick 2.0
Rectangle {
id: mainWindow
width: 640
height: 480
Text {
id: text
width: mainWindow.width
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: "test"
}
ListModel {
id: sampleModel
ListElement {
name: "Arnold"
label: "あーのるど"
}
ListElement {
name: "Redshift"
label: "れっどしふと"
}
ListElement {
name: "Mitsuba"
label: "みつば"
}
}
Component {
id: sampleViewDelegate
Item {
width: parent.width
height: 40
Column {
Text { text: 'Name:' + name }
Text { text: 'label:' + label }
}
MouseArea {
anchors.fill: parent
onClicked: sampleList.currentIndex = index
}
}
}
ListView {
id: sampleList
anchors.fill: parent
model: sampleModel
focus: true
delegate: sampleViewDelegate
highlight: Rectangle {
color: 'grey'
Text {
anchors.centerIn: parent
text: 'Hello ' + model.get(sampleList.currentIndex).name
color: 'white'
}
}
onCurrentItemChanged: {
console.log(model.get(sampleList.currentIndex).name + ' selected')
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment