Capturing a screen or window.
Screen Capture demonstrates how to capture a screen or window using QScreenCapture and QWindowCapture . The example shows a list of screens and windows and displays a live preview of the selected item using a QMediaCaptureSession 和 QVideoWidget . Capturing can be started and stopped with a button .
要运行范例从 Qt Creator ,打开 欢迎 模式,然后选择范例从 范例 。更多信息,拜访 构建和运行范例 .
The example consists of three custom classes. The UI and all screen capture functionality is implemented in the class ScreenCapturePreview. The classes ScreenListModel and WindowListModel only serve as models behind the two QListView widgets. The main function creates a ScreenCapturePreview object, which in turn creates instances of QScreenCapture and QWindowCapture ,和 QMediaCaptureSession and QVideoWidget , in addition to all the UI widgets.
The screen and window models are populated with the return values of QGuiApplication::screens () 和 QWindowCapture::capturableWindows () 分别。
When a list item is selected, it is connected to the QScreenCapture 对象采用 setScreen (), or to the QWindowCapture 对象采用 setWindow (). The capture object is connected to the QMediaCaptureSession 对象采用 setScreenCapture () 和 setWindowCapture (), respectively. The capture session in turn is connected to the QVideoWidget 对象采用 setVideoOutput (). Thus, the capture output is previewed in the video widget on the right hand side of the UI.
The start/stop button calls QScreenCapture::start () 和 QScreenCapture::stop (),或 QWindowCapture::start () 和 QWindowCapture::stop ().
A QMessageBox pops up if the errorOccurred 信号发射。