Multiple QML files with main
-
So I started a new project. And I'm not quite sure which is the best approach.
I have several qml files (each for different pages):
- Idle Page
- Welcome Page
(for the beginning, a "Help" page is coming soon).
The Idle Page is the first thing displayed to the user. He can click anywhere and the Welcome Page pops up. Which is exactly the same size (I hope this makes sense).
Currently I'm doing it a kind of "hacky way" (in Python you would say: "It's not Pythonic")
So here's what I have so far:IDLE SCREEN:
import QtQuick 2.0 Item { Rectangle{ anchors.fill: parent color: white } Image { id: background source: "/Assets/Img/idle_screen_2.png" anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: 50 height: 700 width: 1600 } Text{ id: idleText anchors.top: background.bottom anchors.horizontalCenter: background.horizontalCenter anchors.topMargin: 60 text: qsTr("Please use your RFID card or App\nto start the charging process!") font.pointSize: 20 font.family: "Helvetica" } MouseArea{ signal changeToPage2 anchors.fill: parent onClicked: {lm.source = "WelcomeScreen.qml"} } LoadManager{ id: lm } }
LOADER (which is / should not be necessary?)
import QtQuick 2.0 Loader{ id: pageLoader anchors.fill: parent }
MAIN
import QtQuick 2.15 import QtQuick.Window 2.15 import de.martingebske 1.0 Window { width: 1920 height: 1080 visible: true title: qsTr("HPC") id: root ScreenHandler{ id: screenHandler } LoadManager{ id: lm source: "IdleScreen.qml" } }
The Welcome Screen is the same as the Idle Screen but with a different image and different Text.
SO MY QUESTION IS:
I don't think this is the proper way to change the QML "Views". Currently I'm rendering one Screen over the other. Which is a potential Performance issue (I think?).
It works but it feels wrong. I thought about inserting a C++ class to manage the loading process (i.e. telling the "Load Manager" what to do.Are there any better, more "QML-esque" ways to achieve this?