[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] QQmlApplicationEngine and QGuiApplication
From: Daniel Krause <madakr () web ! de>
Date: 2016-02-25 15:43:19
Message-ID: CAMiLiKipndU5yPdzKRfv8+XGSnnSj9zvUL_Rgy+pROWKcGQJCg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/related)]
[Attachment #4 (multipart/alternative)]
Hello,
I am new to PyQt and having trouble to include QML-Code into an python
application.
The QML-File (main.qml) I can build in a project in QtCreator (a Qt Quick
Application was used to create the project).
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtQml.Models 2.1
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
MainForm {
id: mainForm1
anchors.fill: parent
SplitView {
id: splitView1
width: 100
anchors.left: parent.left
anchors.leftMargin: 36
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
anchors.top: parent.top
anchors.topMargin: 8
orientation: Qt.Vertical
Button {
id: btn_welcome
x: 49
y: 21
text: qsTr("Welcome")
}
Button {
id: btn_database
x: 49
y: 50
text: qsTr("Database")
}
MouseArea {
id: mouseArea1
x: 0
y: 191
width: 100
height: 100
}
}
}
}
It results in the following window:
[image: Inline-Bild 1]
To create the application in Python I tried to use QGuiApplication
and QQmlApplicationEngine.
main.py and main.qml are located in the same directory:
import sys
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtGui import QGuiApplication
if __name__ == '__main__':
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine("main.qml")
print(engine)
sys.exit(app.exec_())
The print()-statement is never executed, no window is appearing.
What did I miss?
Thanks in advance
Daniel
[Attachment #7 (text/html)]
<div dir="ltr"><span style="font-size:12.8px">Hello,</span><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">I am new to PyQt and \
having trouble to include QML-Code into an python application.</div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">The QML-File \
(main.qml) I can build in a project in QtCreator (a Qt Quick Application was used to \
create the project).</div><div style="font-size:12.8px"><br></div><div \
style="font-size:12.8px"><div>import QtQuick 2.5</div><div>import QtQuick.Controls \
1.4</div><div>import QtQuick.Dialogs 1.2</div><div>import QtQml.Models \
2.1</div><div><br></div><div>ApplicationWindow {</div><div> visible: \
true</div><div> width: 640</div><div> height: 480</div><div> title: \
qsTr("Hello World")</div><div><br></div><div> menuBar: MenuBar \
{</div><div> Menu {</div><div> title: \
qsTr("File")</div><div> MenuItem {</div><div> \
text: qsTr("&Open")</div><div> onTriggered: \
console.log("Open action triggered");</div><div> \
}</div><div> MenuItem {</div><div> text: \
qsTr("Exit")</div><div> onTriggered: \
Qt.quit();</div><div> }</div><div> }</div><div> \
}</div><div><br></div><div> MainForm {</div><div> id: \
mainForm1</div><div> anchors.fill: parent</div><div><br></div><div> \
SplitView {</div><div> id: splitView1</div><div> \
width: 100</div><div> anchors.left: parent.left</div><div> \
anchors.leftMargin: 36</div><div> anchors.bottom: \
parent.bottom</div><div> anchors.bottomMargin: 8</div><div> \
anchors.top: parent.top</div><div> anchors.topMargin: 8</div><div> \
orientation: Qt.Vertical</div><div><br></div><div><br></div><div> \
Button {</div><div> id: btn_welcome</div><div> \
x: 49</div><div> y: 21</div><div> text: \
qsTr("Welcome")</div><div> }</div><div><br></div><div> \
Button {</div><div> id: btn_database</div><div> \
x: 49</div><div> y: 50</div><div> text: \
qsTr("Database")</div><div> }</div><div><br></div><div> \
MouseArea {</div><div> id: mouseArea1</div><div> \
x: 0</div><div> y: 191</div><div> \
width: 100</div><div> height: 100</div><div> \
}</div><div> }</div><div> }</div><div>}</div></div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">It results in the \
following window:</div><div style="font-size:12.8px"><img \
src="cid:ii_1530fb7a3e1f8292" alt="Inline-Bild 1" width="412" height="329" class="" \
tabindex="0"><br></div><div style="font-size:12.8px"><br></div><div \
style="font-size:12.8px">To create the application in Python I tried to use \
QGuiApplication and QQmlApplicationEngine. </div><div \
style="font-size:12.8px">main.py and main.qml are located in the same \
directory:</div><div style="font-size:12.8px"><br></div><div \
style="font-size:12.8px"><div>import sys</div><div>from PyQt5.QtQml import \
QQmlApplicationEngine</div><div>from PyQt5.QtGui import \
QGuiApplication</div><div><br></div><div>if __name__ == \
'__main__':</div><div> app = QGuiApplication(sys.argv)</div><div> \
engine = QQmlApplicationEngine("main.qml")</div><div> \
print(engine)</div><div> sys.exit(app.exec_())</div></div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">The \
print()-statement is never executed, no window is appearing.</div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">What did I \
miss?</div><div style="font-size:12.8px"><br></div><div \
style="font-size:12.8px">Thanks in advance</div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">Daniel</div></div>
["image.png" (image/png)]
[Attachment #9 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic