Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.



  • @
    DBusConnection c = QDBusConnection::sessionBus();
    QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
    c.send(m);
    @

    This did the trick for me!



  • Hi jkosonen,

    What about MeeGo? What will be the DBus interface and the name.--

    Thanks,
    Jagadish D



  • 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.0

    Rectangle {
    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


Log in to reply