Is there something on SFOS like e.g. Application.minimize() was on BB10 to programmatically minimize an application to its cover? Either from the C++ or QML side, doesn’t matter.
Exactly! Thank you very much!
EDIT: Well, unfortunately, I can’t make it work. The app stays full screen. Either I’m doing something wrong or it simply doesn’t work.
I’ve never thought about this type of function, so I tested it out and it does work.
This method is for Page
, but not the specific page of your app but the ApplicationWindow (the main qml file of your app).
I added an ‘id’ for ApplicationWindow and then referenced it from MouseArea on my FirstPage.qml.
Each time I click a Button, the function is performed and then the app is then set to its cover.
An excerpt from a remote control app for my old Kenwood amplifier with 60 buttons;
main.qml;
import QtQuick 2.0
import Sailfish.Silica 1.0
import "pages"
ApplicationWindow {
id: mainWindow // <------------------------------------ added id here.
initialPage: Component { FirstPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
}
FirstPage.qml;
MouseArea {
id: mouse
anchors.fill: parent
onClicked: {
var xmlhttp = new XMLHttpRequest()
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
vibrate.running = true
buttons.scale = 1.0
console.log("Function: " + button.buttonName[index] + " " + "irCode" + " 0x" + button.irCode[index])
mainWindow.deactivate() // <-------- method place here
}
else buttons.scale = 0.95
}
I did it in a similar way, i.e. added an “id” property for ApplicationWindow (let’s say “id: appwindow”) and then in the initial qml page I’ve placed it in Component.onCompleted,
Component.onCompleted {
appwindow.deactivate()
}
so that it is done automatically. Didn’t work that way. But if it works for you then I’ll further experiment with it.
I want to have my application automatically minimized to cover at launch, because it is kind of app that (once a few settings are configured which then rarely need to be changed) is supposed to just run in the background and do its job. So it saves time if it automatically minimizes itself at launch. Maybe a background service / daemon would be better for that, but I prefer to have it visible so that I remember when it runs and can close it when it is not needed. Besides, the cover shows me some data.
Anyway, I’ll try to delay it with a oneshot timer, let’s see if it helps.
Agreed, I cannot seem to make it happen by using Component.onCompleted, but I did make it happen when using onStatusChanged as well as on MouseArea from my previous post.
I rarely use Component except when using Settings to save app data parameters otherwise, I’m not familiar with its operations. I did read from Qt docs that there is no order of running for onCompleted.
https://doc.qt.io/qt-5/qml-qtqml-component.html#completed-signal
Did you try an on completed within the parent (ie. appwindow) context?
I’ve used a singleshot timer (started from Component.onCompleted) and this way it works, even with interval as short as 100.
Component.onCompleted: minimize_timer.start()
Timer {
id: minimize_timer
repeat: false
interval: 100
onTriggered: appwindow.deactivate()
}