Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Multiple QML files with main
Forum Updated to NodeBB v4.3 + New Features

Multiple QML files with main

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 638 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Meistermosher
    wrote on last edited by
    #1

    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:

    Setup.png

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      flowery
      wrote on last edited by
      #2

      Use StackView ,It will be helpful for screen navigation as well.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved