How can I know if my item is showing?



  • I'd like to do some optimization of my code, and only update my item when it's on the screen. e.g. the screen it's on is now on top of a stack view, or on the current tab of a tab view.

    Is there a signal I can respond to that indicates when an item is visible to the user?

    I'm not changing the visibility of the object, so onVisibilityChanged isn't the right way to go...



  • Do you mean something like dynamically constructing / loading QML objects as you change tabs?
    http://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html

    Qt.createQmlObject || Qt.createComponent()
    

    and

    (object).destroy()
    

    I don't know if it answers that loaded question of visibility... "visible to the user" is a tricky definition. What's yours because objects can be "visible" and treated as such, all the work still has to happen but still not be actually be seen (under layers, no dimensions, uniform colors, off screen/window drawing).



  • No, I wasn't thinking about dynamic loading.

    Consider you have five popups running, and each one has a video in it. The video will continue to render, even if the popup isn't showing.

    Suppose the video is on a tab in a tabbed interface, and you'd like to stop the video from rendering if the tab it's on isn't showing.

    Suppose the video is in a scrollable view, but that part of the scrollable view isn't currently shown.

    Suppose your Qt app has multiple windows, and one of the windows is hiding a window showing the video.

    What I'm really trying to do is improve CPU usage by having Qt do less work when particular items aren't shown. The interfaces are laid out statically, not dynamically, but I want to dynamically control if a video, a graph, or some other control is doing work that will increase CPU usage.



  • @igor_stravinsky

    Suppose the video is on a tab in a tabbed interface, and you'd like to stop the video from rendering if the tab it's on isn't showing.
    Check currentIndex in TabView.

    Suppose the video is in a scrollable view, but that part of the scrollable view isn't currently shown.
    Check viewport in ScrollView.

    Suppose your Qt app has multiple windows, and one of the windows is hiding a window showing the video.
    Here you can look at "visible" property.


Log in to reply
 

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