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 QCamera(position[, parent=None])

QCamera([parent=None])

QCamera(deviceName[, parent=None])

QCamera(cameraInfo[, parent=None])

param parent

QObject

param cameraInfo

QCameraInfo

param deviceName

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

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.

Constant

Description

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

Constant

Description

QCamera.UnloadedState

The initial camera state, with camera not loaded, the camera capabilities except of 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.

Constant

Description

QCamera.LoadedState

The camera is loaded and ready to be configured.

In the Idle state it’s allowed to query camera capabilities, set capture resolution, codecs, etc.

The viewfinder is not active in the loaded state.

Constant

Description

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

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

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

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

The locked state usually means the requested parameter stays the same, except of the cases when the parameter is requested to be constantly updated. For example in continuous focusing mode, the focus is considered locked as long and the object is in focus, even while the actual focusing distance may be constantly changing.

PySide2.QtMultimedia.QCamera.LockChangeReason

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

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

See also

setCaptureMode()

PySide2.QtMultimedia.QCamera.captureModeChanged(arg__1)
Parameters

arg__1CaptureModes

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

deviceQByteArray

Return type

unicode

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.errorString()
Return type

unicode

Returns a string describing a camera’s error state.

PySide2.QtMultimedia.QCamera.exposure()
Return type

QCameraExposure

Returns the camera exposure control object.

PySide2.QtMultimedia.QCamera.focus()
Return type

QCameraFocus

Returns the camera focus control object.

PySide2.QtMultimedia.QCamera.imageProcessing()
Return type

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()

Open the camera device. The camera state is changed to LoadedStatus .

It’s not necessary to explcitly load the camera, unless unless the application have to read the supported camera settings and change the default depending on the camera capabilities.

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

PySide2.QtMultimedia.QCamera.lockFailed()
PySide2.QtMultimedia.QCamera.lockStatus(lock)
Parameters

lockLockType

Return type

LockStatus

Returns the lock status for a given lockType .

PySide2.QtMultimedia.QCamera.lockStatus()
Return type

LockStatus

Returns the status of requested camera settings locks.

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

See also

captureMode()

PySide2.QtMultimedia.QCamera.setViewfinder(surface)
Parameters

surfaceQAbstractVideoSurface

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.setViewfinder(viewfinder)
Parameters

viewfinderQGraphicsVideoItem

Sets the QGraphicsVideoItem based camera viewfinder . The previously set viewfinder is detached.

PySide2.QtMultimedia.QCamera.setViewfinder(viewfinder)
Parameters

viewfinderQVideoWidget

Sets the QVideoWidget based camera viewfinder . The previously set viewfinder is detached.

PySide2.QtMultimedia.QCamera.setViewfinderSettings(settings)
Parameters

settingsQCameraViewfinderSettings

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 error() 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

PySide2.QtMultimedia.QCamera.stateChanged(state)
Parameters

stateState

PySide2.QtMultimedia.QCamera.status()
Return type

Status

PySide2.QtMultimedia.QCamera.statusChanged(status)
Parameters

statusStatus

PySide2.QtMultimedia.QCamera.stop()

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

PySide2.QtMultimedia.QCamera.supportedLocks()
Return type

LockTypes

Returns the lock types, camera supports.

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

settingsQCameraViewfinderSettings

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

settingsQCameraViewfinderSettings

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

settingsQCameraViewfinderSettings

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

settingsQCameraViewfinderSettings

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()

Close the camera device and deallocate the related resources. The camera state is changed to UnloadedStatus .

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

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()