屏幕捕捉示例
捕捉屏幕或窗口
屏幕捕捉演示了如何使用QScreenCapture 和QWindowCapture 捕捉屏幕或窗口。该示例使用QMediaCaptureSession 和QVideoWidget 显示屏幕和窗口列表,并显示所选项目的实时预览。捕捉可通过button 启动和停止。
运行示例
运行示例 Qt Creator,打开Welcome 模式并从Examples 中选择示例。更多信息,请参阅Qt Creator: 教程:构建和运行。
应用程序结构
该示例由三个自定义类组成。用户界面和所有屏幕捕获功能都在 ScreenCapturePreview 类中实现。类 ScreenListModel 和 WindowListModel 仅作为两个QListView 小部件背后的模型。主函数会创建一个 ScreenCapturePreview 对象,该对象又会创建QScreenCapture 和QWindowCapture 以及QMediaCaptureSession 和QVideoWidget 的实例,此外还会创建所有用户界面部件。
屏幕和窗口模型分别由QGuiApplication::screens() 和QWindowCapture::capturableWindows() 的返回值填充。
当选择一个列表项时,它将通过setScreen() 连接到QScreenCapture 对象,或通过setWindow() 连接到QWindowCapture 对象。捕获对象分别通过setScreenCapture() 和setWindowCapture() 连接到QMediaCaptureSession 对象。捕获会话则通过setVideoOutput() 连接到QVideoWidget 对象。因此,捕捉输出会在用户界面右侧的视频窗口小部件中预览。
开始/停止按钮调用QScreenCapture::start() 和QScreenCapture::stop() 或QWindowCapture::start() 和QWindowCapture::stop() 。
如果发出errorOccurred 信号,则会弹出QMessageBox 。
© 2025 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.