You can solve this by adding a Container
around the outermost Container
in the QML file, and setting its background
to Color.Black
. Then added an id
to the formerly outermost Container
and implement an onScreenEnabled(enabled)
function to show or hide it.
Container {
background: Color.Black
Container {
id: callContainer
...
}
}
function onScreenEnabled(enabled) {
callContainer.visible = enabled;
}
In the .cpp file, use the proximity sensor's reading to emit a signal to enable or disable the screen:
void CallProgress::checkReading() {
bool isClose = proximitySensor->reading()->close();
this->SetScreenEnabled(!isClose);
}
void CallProgress::SetScreenEnabled(const bool enabled) {
emit screenEnabled(enabled);
}
Add the signal and function declarations to the .h file. In the .qml file, connect the emitted signal to the corresponding QML function.
This will hide the UI whenever the proximity sensor's readings detect that the user is close to the screen.