QCamera

The QCamera class provides interface for system camera devices. More

Inheritance diagram of PySide2.QtMultimedia.QCamera

Synopsis

Functions

Slots

Signals

Static functions

Detailed Description

QCamera can be used with QCameraViewfinder for viewfinder display, QMediaRecorder for video recording and QCameraImageCapture for image taking.

You can use QCameraInfo to list available cameras and choose which one to use.

const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo &cameraInfo : cameras) {
    if (cameraInfo.deviceName() == "mycamera")
        camera = new QCamera(cameraInfo);
}

See the camera overview for more information.

class PySide2.QtMultimedia.QCamera(position[, parent=None])

PySide2.QtMultimedia.QCamera([parent=None])

PySide2.QtMultimedia.QCamera(deviceName[, parent=None])

PySide2.QtMultimedia.QCamera(cameraInfo[, parent=None])

param parent

PySide2.QtCore.QObject

param cameraInfo

PySide2.QtMultimedia.QCameraInfo

param deviceName

PySide2.QtCore.QByteArray

param position

Position

Construct a QCamera which uses a hardware camera located a the specified position .

For example on a mobile phone it can be used to easily choose between front-facing and back-facing cameras.

If no camera is available at the specified position or if position is UnspecifiedPosition , the default camera is used.

Construct a QCamera with a parent .

PySide2.QtMultimedia.QCamera.Status

This enum holds the current status of the camera.

Constant

Description

QCamera.ActiveStatus

The camera has been started and can produce data. The viewfinder displays video frames in active state. Depending on backend, changing some camera settings like capture mode, codecs or resolution in ActiveState may lead to changing the camera status to and while the settings are applied and back to when the camera is ready.

QCamera.StartingStatus

The camera is starting in result of state transition to ActiveState . The camera service is not ready to capture yet.

QCamera.StoppingStatus

The camera is stopping in result of state transition from ActiveState to LoadedState or UnloadedState .

QCamera.StandbyStatus

The camera is in the power saving standby mode. The camera may come to the standby mode after some time of inactivity in the LoadedState state.

QCamera.LoadedStatus

The camera is loaded and ready to be configured. This status indicates the camera device is opened and it’s possible to query for supported image and video capture settings, like resolution, framerate and codecs.

QCamera.LoadingStatus

The camera device loading in result of state transition from UnloadedState to LoadedState or ActiveState .

QCamera.UnloadingStatus

The camera device is unloading in result of state transition from LoadedState or ActiveState to UnloadedState .

QCamera.UnloadedStatus

The initial camera status, with camera not loaded. The camera capabilities including supported capture settings may be unknown.

QCamera.UnavailableStatus

The camera or camera backend is not available.

PySide2.QtMultimedia.QCamera.State

This enum holds the current state of the camera.

Constant

Description

QCamera.UnloadedState

The initial camera state, with camera not loaded. The camera capabilities, except supported capture modes, are unknown. While the supported settings are unknown in this state, it’s allowed to set the camera capture settings like codec, resolution, or frame rate.

QCamera.LoadedState

The camera is loaded and ready to be configured. In this state it’s allowed to query camera capabilities, set capture resolution, codecs, etc. The viewfinder is not active in the loaded state. The camera consumes power in the loaded state.

QCamera.ActiveState

In the active state as soon as camera is started the viewfinder displays video frames and the camera is ready for capture.

PySide2.QtMultimedia.QCamera.CaptureMode

This enum holds the capture mode of the camera.

Constant

Description

QCamera.CaptureViewfinder

Camera is only configured to display viewfinder.

QCamera.CaptureStillImage

Camera is configured for still frames capture.

QCamera.CaptureVideo

Camera is configured for video capture.

PySide2.QtMultimedia.QCamera.Error

This enum holds the last error code.

Constant

Description

QCamera.NoError

No errors have occurred.

QCamera.CameraError

An error has occurred.

QCamera.InvalidRequestError

System resource doesn’t support requested functionality.

QCamera.ServiceMissingError

No camera service available.

QCamera.NotSupportedFeatureError

The feature is not supported.

PySide2.QtMultimedia.QCamera.LockStatus

This enum holds the overall status for all the requested camera locks.

Constant

Description

QCamera.Unlocked

The application is not interested in camera settings value. The camera may keep this parameter without changes, this is common with camera focus, or adjust exposure and white balance constantly to keep the viewfinder image nice.

QCamera.Searching

The application has requested the camera focus, exposure or white balance lock with searchAndLock() . This state indicates the camera is focusing or calculating exposure and white balance.

QCamera.Locked

The camera focus, exposure or white balance is locked. The camera is ready to capture, application may check the exposure stays the same, parameters. The Locked status usually means the requested parameter except in the cases when the parameter is requested to be constantly updated. For example, in continuous focusing mode, the focus is considered locked as long as the object is in focus, even while the actual focusing distance may be constantly changing.

PySide2.QtMultimedia.QCamera.LockChangeReason

This enum holds the reason why the camera lock status changed.

Constant

Description

QCamera.UserRequest

The lock status changed in result of user request, usually to unlock camera settings.

QCamera.LockAcquired

The lock status successfuly changed to Locked .

QCamera.LockFailed

The camera failed to acquire the requested lock in result of autofocus failure, exposure out of supported range, etc.

QCamera.LockLost

The camera is not able to maintain the requested lock any more. Lock status is changed to Unlocked .

QCamera.LockTemporaryLost

The lock is lost, but the camera is working hard to reacquire it. This value may be used in continuous focusing mode, when the camera loses the focus, the focus lock state is changed to Qcamera::Searching with reason.

PySide2.QtMultimedia.QCamera.LockType

This enum holds the camera lock type.

Constant

Description

QCamera.NoLock

QCamera.LockExposure

Lock camera exposure.

QCamera.LockWhiteBalance

Lock the white balance.

QCamera.LockFocus

Lock camera focus.

PySide2.QtMultimedia.QCamera.Position

This enum specifies the physical position of the camera on the system hardware.

Constant

Description

QCamera.UnspecifiedPosition

The camera position is unspecified or unknown.

QCamera.BackFace

The camera is on the back face of the system hardware. For example on a mobile device, it means it is on the opposite side to that of the screen.

QCamera.FrontFace

The camera is on the front face of the system hardware. For example on a mobile device, it means it is on the same side as that of the screen. Viewfinder frames of front-facing cameras are mirrored horizontally, so the users can see themselves as looking into a mirror. Captured images or videos are not mirrored.

See also

position()

static PySide2.QtMultimedia.QCamera.availableDevices()
Return type

Note

This function is deprecated.

Returns a list of camera device’s available from the default service provider.

PySide2.QtMultimedia.QCamera.captureMode()
Return type

CaptureModes

The type of media (video or still images), the camera is configured to capture.

It’s allowed to change capture mode in any camera state, but if the camera is currently active, chaging capture mode is likely to lead to camera status chaged to LoadedStatus , LoadingStatus , and when the camera is ready to ActiveStatus .

PySide2.QtMultimedia.QCamera.captureModeChanged(arg__1)
Parameters

arg__1CaptureModes

static PySide2.QtMultimedia.QCamera.deviceDescription(device)
Parameters

devicePySide2.QtCore.QByteArray

Return type

str

Note

This function is deprecated.

Returns the description of the device .

PySide2.QtMultimedia.QCamera.error()
Return type

Error

Returns the error state of the object.

PySide2.QtMultimedia.QCamera.error(arg__1)
Parameters

arg__1Error

PySide2.QtMultimedia.QCamera.errorOccurred(arg__1)
Parameters

arg__1Error

PySide2.QtMultimedia.QCamera.errorString()
Return type

str

Returns a string describing a camera’s error state.

PySide2.QtMultimedia.QCamera.exposure()
Return type

PySide2.QtMultimedia.QCameraExposure

Returns the camera exposure control object.

PySide2.QtMultimedia.QCamera.focus()
Return type

PySide2.QtMultimedia.QCameraFocus

Returns the camera focus control object.

PySide2.QtMultimedia.QCamera.imageProcessing()
Return type

PySide2.QtMultimedia.QCameraImageProcessing

Returns the camera image processing control object.

PySide2.QtMultimedia.QCamera.isCaptureModeSupported(mode)
Parameters

modeCaptureModes

Return type

bool

Returns true if the capture mode is suported.

PySide2.QtMultimedia.QCamera.load()

Opens the camera device. The camera state is changed to LoadedState .

It’s not necessary to explicitly load the camera, unless the application needs to read the supported camera settings and change the default values according to the camera capabilities.

In all the other cases, it’s possible to start the camera directly from the unloaded state.

/sa UnloadedState

PySide2.QtMultimedia.QCamera.lockFailed()
PySide2.QtMultimedia.QCamera.lockStatus()
Return type

LockStatus

This property holds The overall status for all the requested camera locks..

PySide2.QtMultimedia.QCamera.lockStatus(lock)
Parameters

lockLockType

Return type

LockStatus

Returns the lock status for a given lockType .

PySide2.QtMultimedia.QCamera.lockStatusChanged(status, reason)
Parameters
PySide2.QtMultimedia.QCamera.lockStatusChanged(lock, status, reason)
Parameters
PySide2.QtMultimedia.QCamera.locked()
PySide2.QtMultimedia.QCamera.requestedLocks()
Return type

LockTypes

Returns the requested lock types.

PySide2.QtMultimedia.QCamera.searchAndLock()

Lock all the supported camera settings.

PySide2.QtMultimedia.QCamera.searchAndLock(locks)
Parameters

locksLockTypes

Locks the camera settings with the requested locks , including focusing in the single autofocus mode, exposure and white balance if the exposure and white balance modes are not manual.

The camera settings are usually locked before taking one or multiple still images, in responce to the shutter button being half pressed.

The locked() signal is emitted when camera settings are successfully locked, otherwise lockFailed() is emitted.

QCamera also emits lockStatusChanged ( LockType , LockStatus ) on individual lock status changes and lockStatusChanged ( LockStatus ) signal on composite status changes.

Locking serves two roles: it initializes calculation of automatic parameter (focusing, calculating the correct exposure and white balance) and allows to keep some or all of those parameters during number of shots.

If the camera doesn’t support keeping one of parameters between shots, the related lock state changes to Unlocked .

It’s also acceptable to relock already locked settings, depending on the lock parameter this initiates new focusing, exposure or white balance calculation.

PySide2.QtMultimedia.QCamera.setCaptureMode(mode)
Parameters

modeCaptureModes

The type of media (video or still images), the camera is configured to capture.

It’s allowed to change capture mode in any camera state, but if the camera is currently active, chaging capture mode is likely to lead to camera status chaged to LoadedStatus , LoadingStatus , and when the camera is ready to ActiveStatus .

PySide2.QtMultimedia.QCamera.setViewfinder(surface)
Parameters

surfacePySide2.QtMultimedia.QAbstractVideoSurface

Sets a video surface as the viewfinder of a camera.

If a viewfinder has already been set on the camera the new surface will replace it.

PySide2.QtMultimedia.QCamera.setViewfinderSettings(settings)
Parameters

settingsPySide2.QtMultimedia.QCameraViewfinderSettings

Sets the viewfinder settings .

If some parameters are not specified, or null settings are passed, the camera will choose default values.

If the camera is used to capture videos or images, the viewfinder settings might be ignored if they conflict with the capture settings. You can check the actual viewfinder settings once the camera is in the QCamera::ActiveStatus status.

Changing the viewfinder settings while the camera is in the ActiveState state may cause the camera to be restarted.

See also

viewfinderSettings() supportedViewfinderResolutions() supportedViewfinderFrameRateRanges() supportedViewfinderPixelFormats()

PySide2.QtMultimedia.QCamera.start()

Starts the camera.

State is changed to ActiveState if camera is started successfully, otherwise errorOccurred() signal is emitted.

While the camera state is changed to ActiveState , starting the camera service can be asynchronous with the actual status reported with status property.

PySide2.QtMultimedia.QCamera.state()
Return type

State

This property holds The current state of the camera object..

PySide2.QtMultimedia.QCamera.stateChanged(state)
Parameters

stateState

PySide2.QtMultimedia.QCamera.status()
Return type

Status

This property holds The current status of the camera object..

PySide2.QtMultimedia.QCamera.statusChanged(status)
Parameters

statusStatus

PySide2.QtMultimedia.QCamera.stop()

Stops the camera. The camera state is changed from ActiveState to LoadedState .

In this state, the camera still consumes power.

See also

unload() UnloadedState

PySide2.QtMultimedia.QCamera.supportedLocks()
Return type

LockTypes

Returns the lock types that the camera supports.

PySide2.QtMultimedia.QCamera.supportedViewfinderFrameRateRanges([settings=QCameraViewfinderSettings()])
Parameters

settingsPySide2.QtMultimedia.QCameraViewfinderSettings

Return type

Returns a list of supported viewfinder frame rate ranges.

This is a convenience function which retrieves unique frame rate ranges from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to frame rate ranges supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

See also

minimumFrameRate() maximumFrameRate() setViewfinderSettings()

PySide2.QtMultimedia.QCamera.supportedViewfinderPixelFormats([settings=QCameraViewfinderSettings()])
Parameters

settingsPySide2.QtMultimedia.QCameraViewfinderSettings

Return type

Returns a list of supported viewfinder pixel formats.

This is a convenience function which retrieves unique pixel formats from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to pixel formats supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

See also

pixelFormat() setViewfinderSettings()

PySide2.QtMultimedia.QCamera.supportedViewfinderResolutions([settings=QCameraViewfinderSettings()])
Parameters

settingsPySide2.QtMultimedia.QCameraViewfinderSettings

Return type

Returns a list of supported viewfinder resolutions.

This is a convenience function which retrieves unique resolutions from the supported settings.

If non null viewfinder settings are passed, the returned list is reduced to resolutions supported with partial settings applied.

The camera must be loaded before calling this function, otherwise the returned list is empty.

See also

resolution() setViewfinderSettings()

PySide2.QtMultimedia.QCamera.supportedViewfinderSettings([settings=QCameraViewfinderSettings()])
Parameters

settingsPySide2.QtMultimedia.QCameraViewfinderSettings

Return type

Returns a list of supported viewfinder settings.

The list is ordered by preference; preferred settings come first.

The optional settings argument can be used to conveniently filter the results. If settings is non null, the returned list is reduced to settings matching the given partial settings .

The status of the camera must be LoadedStatus before calling this function, otherwise the returned list is empty.

See also

setViewfinderSettings() supportedViewfinderResolutions() supportedViewfinderFrameRateRanges() supportedViewfinderPixelFormats()

PySide2.QtMultimedia.QCamera.unload()

Closes the camera device and deallocates the related resources. The camera state is changed to UnloadedState .

PySide2.QtMultimedia.QCamera.unlock()

Unlock all the requested camera locks.

PySide2.QtMultimedia.QCamera.unlock(locks)
Parameters

locksLockTypes

Unlocks the camera settings specified with locks or cancel the current locking if one is active.

PySide2.QtMultimedia.QCamera.viewfinderSettings()
Return type

PySide2.QtMultimedia.QCameraViewfinderSettings

Returns the viewfinder settings being used by the camera.

Settings may change when the camera is started, for example if the viewfinder settings are undefined or if unsupported values are set.

If viewfinder settings are not supported by the camera, it always returns a null QCameraViewfinderSettings object.

See also

setViewfinderSettings()