How to minize/hide app with QML?
-
Is it possible to minimize or hide application with QML so that it would e.g. display task switcher on N900? Qt object seems to only contain method for quitting?
-
You can expose your top-level window to QML:
@MainWindow::MainWindow()
{
...
QDeclarativeView *view = new QDeclarativeView(this);
view->context()->setContextProperty("mainWindow", this);
...
}@And then from QML, for example:
@MouseArea {
onClicked: mainWindow.showMinimized()
}@ -
Thanks for a quick response. Any easy method to do this in Qt Quick Application where QmlApplicationViewer code is generated automatically?
-
I was able to add this to QmlApplicationViewer constructor:
@
engine()->rootContext()->setContextProperty("mainWindow", this);
@
...but when I call either mainWindow.hide() or mainWindow.showMinimized() in QML then the application quits and doesn't go in to background as expected on N900. -
For generated QmlApplicationViewer, try something like this:
@int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QmlApplicationViewer viewer;/* publish viewer class to QML */ viewer.rootContext()->setContextProperty("QmlApplicationViewer", (QObject *)&viewer); viewer.setMainQmlFile(QLatin1String("qml/CurrentAppli/main.qml")); viewer.showExpanded(); return app.exec();
}
@And then in your QML file:
@
import QtQuick 1.0Rectangle {
id:screen... onSomeEvent { QmlApplicationViewer.hide(); } ... onSomeEvent { QmlApplicationViewer.show() } ...
}
@
let me know if this is working for you.
Bill -
billouparis, it worked for me, thanks!
I had to add <QDeclarativeContext> for it to work.
Also, it doesn't give good code completion :(
But it works...I used QmlApplicationViewer.showMinimized(); //because hide() - hides it in the processes