画面キャプチャの例
画面やウィンドウのキャプチャ
スクリーンキャプチャでは、QScreenCapture とQWindowCapture を使用して、画面またはウィンドウをキャプチャする方法を示します。この例では、画面とウィンドウのリストを表示し、QMediaCaptureSession とQVideoWidget を使用して選択したアイテムのライブ プレビューを表示します。キャプチャは、button で開始および停止できます。
例の実行
から例を実行する。 Qt Creatorから例を実行するには、Welcome モードを開き、Examples から例を選択します。詳細については、Qt Creator: チュートリアル を参照:ビルドと実行。
アプリケーションの構造
このサンプルは3つのカスタムクラスから構成されています。UIとすべてのスクリーンキャプチャ機能は、ScreenCapturePreviewクラスに実装されています。ScreenListModelクラスとWindowListModelクラスは、2つのQListView ウィジェットの背後にあるモデルとしてのみ機能します。メイン関数はScreenCapturePreviewオブジェクトを作成し、そのオブジェクトはすべてのUIウィジェットに加えて、QScreenCapture 、QWindowCapture 、QMediaCaptureSession 、QVideoWidget のインスタンスを作成します。
スクリーン・モデルとウィンドウ・モデルには、それぞれQGuiApplication::screens() とQWindowCapture::capturableWindows() の戻り値が入力される。
リスト・アイテムが選択されると、setScreen ()でQScreenCapture オブジェクトに接続され、setWindow ()でQWindowCapture オブジェクトに接続されます。キャプチャ・オブジェクトは、それぞれsetScreenCapture ()とsetWindowCapture ()でQMediaCaptureSession オブジェクトに接続される。キャプチャセッションはsetVideoOutput() でQVideoWidget オブジェクトに接続されます。このように、キャプチャ出力はUIの右側にあるビデオ・ウィジェットでプレビューされます。
スタート/ストップ・ボタンは、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.