画面キャプチャの例

画面やウィンドウのキャプチャ

スクリーンキャプチャではQScreenCaptureQWindowCapture を使用して、画面またはウィンドウをキャプチャする方法を示します。この例では、画面とウィンドウのリストを表示し、QMediaCaptureSessionQVideoWidget を使用して選択したアイテムのライブ プレビューを表示します。キャプチャは、button で開始および停止できます。

例の実行

から例を実行する。 Qt Creatorからサンプルを実行するには、Welcome モードを開き、Examples からサンプルを選択します。詳細については、Building and Running an Exampleを参照してください。

アプリケーションの構造

このサンプルは、3つのカスタム・クラスで構成されています。UI とすべての画面キャプチャ機能は、ScreenCapturePreview クラスに実装されています。クラス ScreenListModel と WindowListModel は、2 つのQListView ウィジェットの背後のモデルとしてのみ機能します。メイン関数はScreenCapturePreviewオブジェクトを作成し、そのオブジェクトはすべてのUIウィジェットに加えて、QScreenCaptureQWindowCaptureQMediaCaptureSessionQVideoWidget のインスタンスを作成します。

スクリーン・モデルとウィンドウ・モデルには、それぞれQGuiApplication::screens() とQWindowCapture::capturableWindows() の戻り値が入力される。

リスト・アイテムが選択されると、setScreen ()でQScreenCapture オブジェクトに接続され、setWindow ()でQWindowCapture オブジェクトに接続されます。キャプチャ・オブジェクトは、それぞれsetScreenCapture ()とsetWindowCapture ()でQMediaCaptureSession オブジェクトに接続される。キャプチャセッションはsetVideoOutput() でQVideoWidget オブジェクトに接続されます。このように、キャプチャ出力はUIの右側にあるビデオ・ウィジェットでプレビューされます。

スタート/ストップ・ボタンは、QScreenCapture::start ()とQScreenCapture::stop ()、またはQWindowCapture::start ()とQWindowCapture::stop ()を呼び出します。

errorOccurred シグナルが発せられると、QMessageBox がポップアップします。

プロジェクト例 @ code.qt.io

© 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.