이 페이지에서

화면 캡처 예시

화면 또는 창 캡처.

'화면 캡처' 예제는 ` QScreenCapture ` 및 ` QWindowCapture`을 사용하여 화면이나 창을 캡처하는 방법을 보여줍니다. 이 예제에서는 화면 및 창 목록을 표시하고, ` QMediaCaptureSession ` 및 ` QVideoWidget`을 사용하여 선택한 항목의 실시간 미리보기를 표시합니다. 캡처는 ` button`을 사용하여 시작 및 중지할 수 있습니다.

스크린샷 이미지와 함께 화면 목록을 표시하는 UI

예제 실행

다음 경로에서 예제를 실행할 수 있습니다:

애플리케이션 구조

이 예제는 세 개의 사용자 정의 클래스로 구성되어 있습니다. UI와 모든 화면 캡처 기능은 ScreenCapturePreview 클래스에서 구현됩니다. ScreenListModel 및 WindowListModel 클래스는 두 개의 QListView 위젯을 뒷받침하는 모델 역할만 합니다. main 함수는 ScreenCapturePreview 객체를 생성하며, 이 객체는 QScreenCapture 및 QWindowCapture 의 인스턴스와 QMediaCaptureSession 및 QVideoWidget 의 인스턴스를 생성하고, 모든 UI 위젯을 생성합니다.

스크린 및 윈도우 모델은 각각 ` 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

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