Skip to content

Instantly share code, notes, and snippets.

@akdasa
Last active October 23, 2016 09:28
Show Gist options
  • Save akdasa/086abb725390229f9a2c3bacae6d4036 to your computer and use it in GitHub Desktop.
Save akdasa/086abb725390229f9a2c3bacae6d4036 to your computer and use it in GitHub Desktop.
Simple PyQt5/QML application
function log() {
console.log("HELLO!");
}
//import related modules
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2
import "application.js" as App
//window containing the application
ApplicationWindow {
//title of the application
title: qsTr("Hello World")
width: 640
height: 480
//a button in the middle of the content area
Button {
id: btn
text: qsTr("Hello World")
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onClicked: App.log()
}
}
import sys
import os
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
if __name__ == '__main__':
full_directory = os.path.dirname(os.path.abspath(__file__))
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
qml_file = os.path.join(full_directory, "basic.qml")
engine.load(str(qml_file))
window = engine.rootObjects()[0]
window.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment