I have the following cases, I want to use several Qml: "welcome.qml", "create.qml", "dashboard.qml"
in which cases to use QQuickview or QqmlApplicationEngine.?
I am using "QQmlAplicatiobEngine" and search in the object with findChild to get the signal, and handle the logic, If the signal completes a condition, I use the engine.load to load another QML.
python:
class guiBackend(QObject):
def __init__(self):
self.engine = QQmlApplicationEngine()
self.context = self.engine.rootContext()
self.context.setContextProperty("main", self.engine)
self.welcome()
def welcome(self):
self.engine.load("welcome.qml")
self.engine.rootObjects()[0].show()
ob = self.engine.rootObjects()[0]
next = ob.findChild(QObject, "timer")
print(dir(next))
if path.exists('data.some'):
next.change.connect(self.open_account)
else:
next.change.connect(self.create_account)
def create(self):
self.engine.rootObjects()[0].close()
self.engine.load("create.qml")
self.engine.rootObjects()[1].show()
add = ob.findChild(QObject, "addWallet")
recovery = ob.findChild(QObject, "recovery")
add.change.connect(self.add_account)
recovery.change.connect(self.recovery)
#self.open_account load dashboard.qml and self.account load form.qml
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
gui = guiBackend()
sys.exit(app.exec_())
Qml:
ApplicationWindow {
id: welcome
width: 650; height: 390
opacity: 1
visible: true
minimumHeight: 232
minimumWidth:226
title: "open account"
flags: Qt.SplashScreen
Item {
id: element
x: 9
y: 88
width: 560
height: 300
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Timer {
signal change
objectName: "timer"
interval: 5000; running: true; repeat: false
onTriggered: change()
}
Image {
id: image
x: 130
y: 60
width: 342
height: 188
anchors.verticalCenterOffset: -56
anchors.horizontalCenterOffset: 0
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
source: "neirons_logo.png"
fillMode: Image.PreserveAspectFit
}
AnimatedImage {
id: animatedImage
x: 236
y: 200
width: 100
height: 100
source: "loading.gif"
}
}
}
create.qml:
ApplicationWindow {
id: create
width: 210; height: 210
Rectangle {
id: rectangle
x: 70
y: 132
width: 200
height: 200
color: "#72ded8"
anchors.verticalCenterOffset: 0
anchors.horizontalCenterOffset: 0
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
ColumnLayout {
x: 60
y: 73
width: 109
height: 128
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
TextInput {
id: nameAccount
objectName: textAccount
text: qsTr("nameAccount")
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
Layout.preferredHeight: 20
Layout.preferredWidth: 80
verticalAlignment: Text.AlignVCenter
font.pixelSize: 12
}
TextInput {
id: nameAccount
objectName: textAccount
text: qsTr("Name Account")
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
Layout.preferredHeight: 20
Layout.preferredWidth: 80
font.pixelSize: 12
}
}
Button {
signal addinfo
id: submitNameAccount
objectName: submit
x: 50
y: 134
width: 81
height: 23
text: qsTr("Add")
font.bold: true
font.pointSize: 12
anchors.horizontalCenter: parent.horizontalCenter
onClicked: addinfo()
}
}
It's better with QQuickview or QQmlAplicationEngine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…