Main window won’t become visible after a Loader page has closed
-
I'm starting an application that will have several buttons on a main screen, each one of which will spawn new screens. I'm just in the beginning stages trying to find out how exactly I'll do it, so currently I only have one button (just rectangles really) and a text label on the main screen. There's also a Loader to pop up other windows. I've taken out the unimportant formatting info - this is what I have for the main qml file:
@Rectangle {
id: rootWindow; focus: true // This is the main screenonFocusChanged: { rectangle1.visible = true } Loader { id: pageLoader } Rectangle { id: rectangle1 // This is the button that should take us to the 2nd window Text { id: text1; text: "Button 1" } MouseArea { anchors.fill: parent onClicked: { pageLoader.source = "page2.qml"; rectangle1.visible = false } }
}
@I then have another screen defined in page2.qml. This screen has a button that, when pressed, should take me back to the main screen. Here's the file:
@Rectangle { // This is the rectangle for the new screen - it's the same size as the main
id: newPage
focus: trueRectangle { // This is the button that should take us back to the main screen id: rectangle1 Text { id: text1 text: "Go Back" } MouseArea { anchors.fill: parent onClicked: { pageLoader.source = "" newPage.focus = false } } }
}
@
Anyway, I run the application, and I see my main screen just fine. When I press the button, the 2nd screen comes up just fine. When I click the button on that screen to go back to the main, the 2nd screen goes away, but the main screen is blank, i.e. the button isn't visible.Question 1: What am I missing? Why doesn't the button on the first screen become visible after the 2nd screen closes?
Question 2: In general, is this a good approach to building an application with multiple screens?