-1

I am new to QT and want to develop a QT Quick app for the raspberry pi and its touch LCD display. The app should have several screens (sorry, not sure what the right terminology is, with screen I mean a state of the app which fills the whole display of the Raspberry Pi) and there should be buttons to switch between those screens. How is it possible to switch to a different screen when I press a button?

I tried using loader but (right now I am testing on the Desktop not the Raspberry) it opens the qml file in a new window, but I would like to have the content of the original window replaced.

Edit: Yes, I plan using EGLFS. I enclose some code which does in principle what I want. However, I am not sure if this is the right way to do things: I put the screens I want to have into their own qml file, and toggle their visibility through buttons our mouse areas:

main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

ApplicationWindow {
    visible: true
    width: 800
    height: 460
    title: qsTr("Hello World")

    Page1 {
        id: page1
        visible: true
    }

    Page2 {
         id: page2
         visible: false
    }

}

Page1.qml

import QtQuick 2.7
import QtQuick.Controls 2.0

Item {
        Button {
            id: button1
            width: 200
            height: 40
            text: qsTr("To second page")
            onClicked: {
                page2.visible=true
                page1.visible=false
            }
        }
}

Page2.qml

import QtQuick 2.3
import QtQuick.Window 2.2

Item {
    Text {
        id: text1
        x: 181
        y: 153
        text: qsTr("Second Page")
        font.pixelSize: 12
    }

    Rectangle {
        id: rectangle
        x: 252
        y: 222
        width: 200
        height: 200
        color: "#000000"
        border.color: "#f12525"
    }

    MouseArea {
        id: mouseArea
        x: 234
        y: 209
        width: 244
        height: 225
        onClicked:{
            page1.visible=true
            page2.visible=false
        }
    }
}
numberCruncher
  • 595
  • 1
  • 6
  • 25
  • You could show your code, also please be precise in your question, first you talk about raspberry after desktop, consider the version of qt in both, usually it will work but for problems of versions you will not have all the components in raspberry. – eyllanesc May 05 '17 at 17:34
  • I did not post code because I am lost right now regarding which approach to take. Using Quick Controls there are things like StackView, would that be appropriate? Or is it easier to use Loader or States? Regarding Raspberry and Desktop: In the end the application should run on the Raspberry, but right now I am developing on my Desktop. I just mentioned it because one problem with the loader approach I had was that new windows were opened, but on the Raspberry this might behave differently. – numberCruncher May 05 '17 at 20:18
  • Your question is broad and that is off-topic in SO, read [this](https://stackoverflow.com/help/mcve) to improve your question. – eyllanesc May 05 '17 at 20:23
  • Some code of yours would help indeed, because most likely you have a `Window`-descendant as root node in the loaded component, might that be by chance? – derM - not here for BOT dreams May 06 '17 at 09:02
  • The way I was trying earlier had a Window for each screen/qml file, which was probably why always new windows were opened when I connected a mouseArea to the loader. In the example above I use ApplicationWindow from QuickControls, however, I am not sure whether QuickControls or pure Quick is the right choice for me. – numberCruncher May 06 '17 at 13:28

1 Answers1

-1

I would venture to guess that most likely you want to use Qt5's eglfs mode on the raspberry pi. This gets rid of the normal desktop and runs your Qt5 (regular or QML) app full screen. When I last did this, I needed to compile Qt5 myself. That is something you will either want to figure out cross compiling for, or use a RaspberryPi 3 (the results can then be copied to slower Raspberry Pis if desired). I worked from the guide at https://wiki.qt.io/RaspberryPi2EGLFS

It was pretty trivial to run the program then in a window on a linux desktop or full screen on a Raspberry Pi with touch screen (both the special 7" screen or a generic 22" touch display).

A newer looking alternative to using eglfs is apparently the QtWayland Compositor. I haven't used it, but there is an interesting presentation on using it for full screen embedded applications from the most recent (2017) FOSDEM, available here: https://fosdem.org/2017/schedule/event/device_specific_compositors/

Joshua D. Boyd
  • 4,808
  • 3
  • 29
  • 44