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 know when a qml starts to being displayed and when it is hidden
Forum Updated to NodeBB v4.3 + New Features

How to know when a qml starts to being displayed and when it is hidden

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 10.4k Views 2 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.
  • D Offline
    D Offline
    Daniel Chicco
    wrote on last edited by Daniel Chicco
    #1

    I need to create a custom qml ( a rectangle with components inside) that needs to receive information from a service only when it is being displayed, so it must register to the service when starts to be displayed and unregister when it is hidden. I tried using Component.onCompleted and Component.onDestruction but the problem with events is they belongs to the Component lifecycle and not to the Item lifecycle. What events I need to listen to implement the desired behaviour?

    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2
       onVisibleChanged: {
              if (visible)
                  // is being displayed
              else 
                 // is being hidden
      }
      
      1 Reply Last reply
      1
      • X Offline
        X Offline
        xargs1
        wrote on last edited by
        #3

        What exactly do you mean by "displayed" and "hidden"? Hidden by the application? Hidden by a window being minimized or covered by another window?

        D 1 Reply Last reply
        0
        • X xargs1

          What exactly do you mean by "displayed" and "hidden"? Hidden by the application? Hidden by a window being minimized or covered by another window?

          D Offline
          D Offline
          Daniel Chicco
          wrote on last edited by
          #4

          @xargs1 The case I am asking for is when it becomes visible to the user or hidden to the user. You provided a good example, hidden because the user opened a new window and the current one is not displayed anymore, or because I have a StackView and I push a new item to the StackView, in this case the previous item dissapears but if I pop the StackView it appears again. I need to know those changes to start and stop listening to an streaming service. I was thinking to do it inside the item code using some events but if it is not possible I should do it from outside when the parent item make changes to the UI.

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xargs1
            wrote on last edited by
            #5

            StackView provides its own attached property that will tell you when an item becomes visible or hidden. The Window element has a Visibility attached property that might tell you what you want to know, though I doubt it handles "covered by another window".

            1 Reply Last reply
            0
            • johngodJ Offline
              johngodJ Offline
              johngod
              wrote on last edited by
              #6

              @xargs1 by being displayed I mean the window visiblility changed from false to true and being hidden the window visibilty changed from true to false :) I usually use states binded to the windows visibilty, that way I ensure that I only have one windows visible at the time.
              It is up to the developer to choose best option to fit its needs, and this is just one possible example. Of course this wont work in one shows a window above another using the z order, for example.

              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