多输出
“多输出”是一个演示具有多个输出的合成器的示例。
简介
“多输出”示例演示了如何在不同的WaylandOutputs 上,以不同类型的合成方式显示相同的客户端。其中一个输出将客户端以统一的网格形式显示,并缩放为相同大小;另一个输出则是常规的桌面风格交互式合成器窗口。

有关使用 Qt Wayland Compositor ,请参阅“Minimal Qml”示例。
多输出
该示例创建了两个不同的窗口,每个输出对应一个窗口。对于网格视图,我们连接到surfaceRequested 信号。每当客户端创建一个表面时,该信号都会被触发。这使得应用程序能够覆盖对该请求的默认响应,并创建一个自定义的WaylandSurface 。
onSurfaceRequested: (client, id, version) => {
var surface = surfaceComponent.createObject(comp, { } );
surface.initialize(comp, client, id, version);
}接收到信号后,示例会创建一个WaylandQuickItem 作为该表面的视图。该视图可像其他项目一样添加到Qt Quick 场景中。在示例中,我们将其添加到GridView 中。
对于桌面风格的窗口,我们利用XdgShell 扩展的功能。当表面创建完成后,XdgShell 会发出toplevelCreated 信号。
XdgShell {
onToplevelCreated: (toplevel, xdgSurface) => {
var item = chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": xdgSurface } );
item.surface.activated.connect(item.raise);
}
}我们创建一个ShellSurfaceItem ,将XdgToplevel 添加到第二个输出中。这使得用户能够以桌面风格的方式与该表面进行交互。
完成这些步骤后,客户端的内容将在两个窗口中均可见。虽然两个输出端所使用的客户端内容缓冲区相同,但它们以两种不同的方式进行可视化呈现,并为用户提供了不同的交互方式。
注意:为了在 同一合成器中支持多个 Wayland 输出,必须在构建QGuiApplication 对象之前设置Qt::AA_ShareOpenGLContexts 属性。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.