Qt Quick Ultralite 多屏范例

Demonstrates how to use multiple screens in Qt Quick Ultralite.

概述

multiscreen example shows how a single Qt Quick Ultralite application can display content on separate screens.

目标平台

工程结构

The minimal example consists of only two files, CMakeLists.txt and multiscreen.qml .

The CMake project file contains a basic build script and the multiscreen.qml defines the UI.

CMake 工程文件
cmake_minimum_required (VERSION 3.15)
project(multiscreen VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::QuickUltralite)
    find_package(Qul)
endif()
qul_add_target(multiscreen)
qul_target_qml_sources(multiscreen multiscreen.qml)
app_target_setup_os(multiscreen)
app_target_default_entrypoint(multiscreen multiscreen)
if(NOT CMAKE_CROSSCOMPILING AND NOT WIN32)
    add_custom_command(TARGET multiscreen
        COMMAND strip multiscreen -o multiscreen.stripped
        DEPENDS multiscreen)
endif()
							
应用程序 UI
import QtQuick 2.15
import QtQuickUltralite.Layers 1.2
Application {
    Screen {
        backgroundColor: "#41CD52"
        ItemLayer {
            anchors.centerIn: parent
            depth: ItemLayer.Bpp32Alpha
            width: textPrimary.width
            height: textPrimary.height
            Rectangle {
                anchors.fill: parent
                color: "#41CD52"
            }
            Column {
                id: textPrimary
                anchors.centerIn: parent
                spacing: 5
                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    font.pixelSize: 30
                    text: "Qt for MCUs"
                }
                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    font.pixelSize: 20
                    text: "first screen"
                }
            }
        }
    }
    Screen {
        backgroundColor: "#41CD52"
        ItemLayer {
            anchors.centerIn: parent
            depth: ItemLayer.Bpp32Alpha
            width: textSecondary.width
            height: textSecondary.height
            Rectangle {
                anchors.fill: parent
                color: "#41CD52"
            }
            Column {
                id: textSecondary
                anchors.centerIn: parent
                spacing: 5
                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    font.pixelSize: 30
                    text: "Qt for MCUs"
                }
                Text {
                    anchors.horizontalCenter: parent.horizontalCenter
                    font.pixelSize: 20
                    text: "second screen"
                }
            }
        }
    }
}
							

文件: