cancel
Showing results for 
Search instead for 
Did you mean: 

isVisible always return True on item in a not visible scroll list

nico23
Senior III

I have a scroll list lightSoundSelectorScroll made by several items from the container lightSoundItem.

In the view I call lightSoundSelectorScroll.setVisible(false); or lightSoundSelectorScroll.setVisible(true); but, when calling this->isVisible() inside void lightSoundItem::handleTickEvent() I always have true even if I called lightSoundSelectorScroll.setVisible(false); before

Why is that?

1 ACCEPTED SOLUTION

Accepted Solutions
nico23
Senior III

Hi @JohanAstrup 

that makes sense.

I've implemented the function

bool optionsItem::isEffectivelyVisible() const
{
    const Drawable* node = this;
    while (node != nullptr)
    {
        if (!node->isVisible()) return false;
        node = node->getParent();
    }
    return true;
}

to my custom container item, so I can check it in the optionsItem::handleTickEvent()

Not the cleaner solution, as it's polling instead of event-driven, but it works.

View solution in original post

2 REPLIES 2
JohanAstrup
ST Employee

Hello @nico23.

The isVisible() function only checks whether the isVisible property is set on the given widget. It does not check whether the widget is actually shown on the screen. It will e.g. also return true if the alpha value is set to 0, while the isVisible property is still true.

In your case, you toggle the visibility on the parent but check the visibility on the child. However, the child will still have isVisible set to true.
If you want to continue with this approach, you could e.g. give the child a pointer to its parent. Then you can check whether the parent is visible.

Let me know if that makes sense.

Best regards,
Johan

nico23
Senior III

Hi @JohanAstrup 

that makes sense.

I've implemented the function

bool optionsItem::isEffectivelyVisible() const
{
    const Drawable* node = this;
    while (node != nullptr)
    {
        if (!node->isVisible()) return false;
        node = node->getParent();
    }
    return true;
}

to my custom container item, so I can check it in the optionsItem::handleTickEvent()

Not the cleaner solution, as it's polling instead of event-driven, but it works.