summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/screencapture/doc/src/screencapture.qdoc
blob: e0c73863f8ea2e8dcf5046b7e2839fc866515653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example screencapture
    \title Screen Capture Example
    \ingroup multimedia_examples
    \brief Capturing a screen or window.
    \meta {tag} {widgets}

    \e{Screen Capture} demonstrates how to capture a screen or window using QScreenCapture.
    The example shows a list of screens and windows and displays a live preview of the
    selected item using a QMediaCaptureSession and a QVideoWidget. There is also a field
    for inputting a window ID manually including a confirm button, and a button
    to start and stop the capturing.

    \image screencapture.jpg

    \include examples-run.qdocinc

    \section1 Application Structure

    The example consists of three custom classes. The UI and all screen capture functionality
    is implemented in the class ScreenCapturePreview. The classes ScreenlListModel and
    WindowListModel only serves as models behind the two QListView widgets. The main function
    creates a ScreenCapturePreview object, which in turn creates an instance of QScreenCapture,
    QMediaCaptureSession and QVideoWidget in addition to all the UI widgets.

    The lists are populated with the return values of \l QGuiApplication::screens() and
    \l QGuiApplication::allWindows(). The input field is prefilled with a window ID from the latter.

    When a list item is selected or a window ID is input, it is connected to the QScreenCapture object with
    \l QScreenCapture::setScreen(), \l QScreenCapture::setWindow() or \l QScreenCapture::setWindowId().
    The QScreenCapture object is connected to the QMediaCaptureSession object with
    \l QMediaCaptureSession::setScreenCapture(), which in turn is connected to the
    QVideoWidget object with \l QMediaCaptureSession::setVideoOutput(). Thus the
    screen capture output is previewed in the video widget on the right hand side of the UI.

    The Window ID input field is a QLineEdit object that handles both HEX and
    decimal numbers.

    The start/stop button calls \l QScreenCapture::start() and \l QScreenCapture::stop().

    A QMessageBox pops up if the QScreenCapture::errorOccurred signal is emitted.
*/