Skip to content

Instantly share code, notes, and snippets.

@a-andreyev
Last active March 13, 2019 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-andreyev/feff8d672a713d278d144c16744aac26 to your computer and use it in GitHub Desktop.
Save a-andreyev/feff8d672a713d278d144c16744aac26 to your computer and use it in GitHub Desktop.
Qt_for_Python_Tutorial_HelloQML
from PySide2.QtWidgets import QApplication
from PySide2.QtQuick import QQuickView
from PySide2.QtCore import QUrl
import resources
app = QApplication([])
view = QQuickView()
url = QUrl("qrc:///view.qml")
view.setSource(url)
view.show()
app.exec_()
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>view.qml</file>
<file>silicaview.qml</file>
</qresource>
</RCC>
from cx_Freeze import setup, Executable
import sys
PROGRAM_NAME = "Qt_for_Python_Tutorial_HelloQML"
VERSION = "0.0.1"
MAIN_SCRIPT_NAME = "main.py"
bin_includes = []
includefiles = []
if sys.platform == 'linux':
bin_includes.extend(['libpyside2.cpython-34m.so', 'libshiboken2.cpython-34m.so'])
includefiles.extend(['/usr/lib/libshiboken2.cpython-34m.so', '/usr/lib/libpyside2.cpython-34m.so'])
options = {
'build_exe': {
'bin_includes': bin_includes,
# 'bin_path_includes':'/usr/lib',
'include_files': includefiles,
}
}
setup( name = PROGRAM_NAME,
version = VERSION, options=options,
requires=['PySide2', 'shiboken'],
executables = [Executable(MAIN_SCRIPT_NAME)])
import QtQuick 2.0
import Sailfish.Silica 1.0
ApplicationWindow
{
initialPage: sailCalcComponent
Component {
id: sailCalcComponent
Page {
Rectangle {
id: myRect
anchors.fill: parent
color: "transparent"
Button {
id: myButton
anchors.centerIn: parent
text: "Press me"
onClicked: {
myRect.color = Qt.hsla(Math.random(), 0.5, 0.4, 0.4)
}
}
}
}
}
}
import QtQuick 2.0
Rectangle {
id: myRect
anchors.fill: parent
color: "lightgreen"
Text {
id: myText
anchors.centerIn: parent
text: "Hello, world"
font.bold: true
Rectangle {
anchors.fill: parent
anchors.margins: -parent.height/3
color: "white"
radius: height
opacity: 0.5
}
}
Timer {
interval: 500; running: true; repeat: true
onTriggered: {
myRect.color = Qt.hsla(Math.random(), 0.5, 0.4, 1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment