Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to minize/hide app with QML?
Forum Updated to NodeBB v4.3 + New Features

How to minize/hide app with QML?

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 6 Posters 10.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tlaukkanen
    wrote on last edited by
    #1

    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?

    My Blog: <a href="http://www.substanceofcode.com">substanceofcode.com</a>
    Twitter: <a href="http://twitter.com/tlaukkanen">twitter.com/tlaukkanen</a>

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      YetAnotherNick
      wrote on last edited by
      #2

      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()
      }@

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tlaukkanen
        wrote on last edited by
        #3

        Thanks for a quick response. Any easy method to do this in Qt Quick Application where QmlApplicationViewer code is generated automatically?

        My Blog: <a href="http://www.substanceofcode.com">substanceofcode.com</a>
        Twitter: <a href="http://twitter.com/tlaukkanen">twitter.com/tlaukkanen</a>

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tlaukkanen
          wrote on last edited by
          #4

          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.

          My Blog: <a href="http://www.substanceofcode.com">substanceofcode.com</a>
          Twitter: <a href="http://twitter.com/tlaukkanen">twitter.com/tlaukkanen</a>

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jkosonen
            wrote on last edited by
            #5

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

            This did the trick for me!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DJ
              wrote on last edited by
              #6

              Hi jkosonen,

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

              Thanks,
              Jagadish D

              1 Reply Last reply
              0
              • B Offline
                B Offline
                billouparis
                wrote on last edited by
                #7

                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&#40;QLatin1String("qml/CurrentAppli/main.qml"&#41;);
                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

                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  lilian.moraru
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved