How to detect switching from "windowed" to "minimized"...

  • I implemented the onviewmodechanged listener in order to detect the transition between windowed and minimized.

    When the widget is windowed it will start the location service, and it will stop the location service when minimized in order to minimize the load on the battery.

    If I start the widget from the homescreen, the onviewmodechanged event fires, and the mode will be "windowed". When I close the window the taskswitcher screen is shown. (It would be more userfriendly if the homescreen was shown in this case).

    The onviewmodechanged event is not fired until the user looks at the homescreen containing the widget.

    Is there another event that can be used to detect the closing of a "windowed" screen?

  • I've never tried that, but did you give "QHideEvent": a chance?

    Try that and share your results here =)

  • I added eventhandlers to widget.onhide and widget.onshow.

    It turns out that those events are triggered ...

    When the widget is added to the homescreen the following events are fired

    1. onshow()
    2. onviewmodechanged("minimized")
      When another homescreen page is chosen
    3. onhide()
      When the homescreen page containing the widget is chosen
    4. onshow()
      When the widget is tapped
    5. onviewmodechange("windowed")
    6. onhide()
    7. onshow()
      When the window is minimized (using the top-left icon)
    8. onhide()
      When the window is opened again from the taskmanager
    9. onshow()
      When the window is closed (using the top-right icon)
    10. onhide()
      When the homescreen is opened
    11. onshow()
    12. onviewmodechange("minimized")
      When the widget is tapped again
    13. onviewmodechange("windowed")
    14. onhide()
    15. onshow()

    It turns out that the viewMode is changed before the onhide event is triggered, so it is not possible to determine what viewMode is hidden. So this cannot be used to free up resources.

    The viewmode is usually changed before the onshow event, but not when the homescreen widget becomes visible (see events 11) and 12) )...

    I think that these events are not usable for my goals.

    The onviewmodechange event should be used only for adapting layouts on the page and the onshow/onhide events to start/stop cpu intensive ui updates.

    Hopefully some documentation can explain when each of the events is triggered. I would expect event 12) would be triggered before event 11).

  • The main reason behind is that when the window is opened by tapping the widget on the home screen, we have to track the current view mode of the widget, either windowed or minimized.

    However, we can only rely on whether the home screen is shown to update the view mode in your case.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.