The following code samples demonstrate how to set the camera's flash mode. You can extend these instructions and techniques to set other camera properties.
First, you set up a CameraSettings object and add it to the Camera control as an attached object. You can use the id to set and apply a new flash mode setting.
// The Camera control Camera { id: qmlCameraObj // ... attachedObjects: [ // ... CameraSettings { id: camSettings } ] // ... }
To allow your users to choose a flash mode setting and apply it, you can use a DropDown list and a Button. Create a DropDown with the id flashmode_dropdown to display the flash mode options. Use a Button to apply the selected flash mode settings.
// Use a DropDown to select the // preferred flash mode DropDown { id: flashmode_dropdown selectedIndex: 2 title : "Flash Mode" enabled : true Option { text : "Off" // Disable flash } Option { text : "On" // Always use flash } Option { text : "Auto" // Use flash in low light conditions } Option { text : "Light" // The light is on for the duration // that the viewfinder is active } } // ... // The CameraSettings object has the id of camSettings. // The camera id is qmlCameraObj. // The selected index coincides with the enum's numerical // value of the listed flash modes. Button { id: btnApplySettings onClick: { qmlCameraObj.getSettings(camSettings); camSettings.flashMode = flashmode_dropdown.selectedIndex; qmlCameraObj.applySettings(camSettings); } }
Another option for setting the flash mode is to use the Actions bar menu. This option keeps the flash mode settings hidden until the user wants to see them. When the user opens the Actions bar menu and selects a flash mode, the app sets the selected option.
Page { // Actions menu actions: [ ActionItem { title: "Flash Mode: Off" ActionBar.placement: ActionBarPlacement.InOverflow onTriggered: { qmlCameraObj.getSettings(camSettings); camSettings.flashMode = CameraFlashMode.Off; qmlCameraObj.applySettings(camSettings); } }, ActionItem { title: "Flash Mode: On" ActionBar.placement: ActionBarPlacement.InOverflow onTriggered: { qmlCameraObj.getSettings(camSettings); camSettings.flashMode = CameraFlashMode.On; qmlCameraObj.applySettings(camSettings); } }, ActionItem { title: "Flash Mode: Auto" ActionBar.placement: ActionBarPlacement.InOverflow onTriggered: { qmlCameraObj.getSettings(camSettings); camSettings.flashMode = CameraFlashMode.Auto; qmlCameraObj.applySettings(camSettings); } }, ActionItem { title: "Flash Mode: Light" ActionBar.placement: ActionBarPlacement.InOverflow onTriggered: { qmlCameraObj.getSettings(camSettings); camSettings.flashMode = CameraFlashMode.Light; qmlCameraObj.applySettings(camSettings); } } ] // ... }