Controlling the camera
The QCameraFocus
class is mentioned to control the zoom and focus of the camera. Speaking of zoom, Qt supports both optical and digital zoom. As we all know, optical zoom offers a better quality than digital. Hence, optical zoom should take priority over digital.
Drag a horizontal slider and a label to MainWindow pane's verticalLayout
just above the capture button. Name them zoomSlider
and zoomLabel
, respectively. Remember to change the text of zoomLabel
to Zoom
and Horizontal
in alignment
to AlignHCenter
. Since Qt doesn't provide a floating point number slider, we simply multiply 10
to get an integer in the slider. Hence, change the minimum
value of zoomSlider
to 10
, which means zoom by 1.0.
Include QCameraFocus
in mainwindow.h
and add these two private members:
QCameraFocus *cameraFocus; qreal maximumOptZoom;
Tip
Not every camera supports zoom. If it doesn't, the maximum zoom is 1.0, which applies to both optical and digital zoom.
There is a type named...