Last active
September 27, 2017 06:25
-
-
Save yamahigashi/eb5dee98071679c3031765106e3e38dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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