How to capture TabbedComponent's tab active


Hi all,
I used a component inherited from TabbedComponent to show tabs.
At the init time, I added tabs
void init()

m_tabs->addTab(“tab-name-1”, tab-color-1, new myComponentA(), true);
m_tabs->addTab(“tab-name-2”, tab-color-2, new myComponentB(), true);


After initialized, my UI already had 2 tabs with the content of myComponentA,
myComponentB and it didn’t reload again when I clicked to tab1 or tab2.

How can I detect tab1 or tab2 click event to reload UI, because in tab2 I change some value in tab1 and I need to reload it?


I think you should get a callback Component::visibilityChanged() in your displayed component, that you can override to update your values.

Hope that helps.


Thank you so much @daniel you your quickly support :slight_smile: I’m going to try it now


Hi @daniel, visibilityChanged() of all component will be called, so all component will be repainted. Can you tell me how to repaint only one tab which is clicked by user?

One more @daniel, How to do if at init time, my app only init tab1 (because it will show tab1 fisrt, and initialize tab2 will take some time) and tab2 is empty that time, then user click to tab2, tab2 will begin draw its UI.


Just check Component::isVisible() in your visibilityChanged() method, it should only be true for the one component, that is currently shown.

When you add the component to the tab, it should only be created, not being painted.

The question is really, what makes the construction that heavy, that you think you have to optimise that away. The update is already moved to visibilityChanged() now.

Doing the creation on a background thread is a bad idea, since creating Components and adding them to the components hierarchy needs to happen on the message thread.


That’s really good support. Thank you so much @daniel


Why not override TabbedComponent::currentTabChanged() ?



Because then you code things in an unrelated structure. The Component has the knowledge and access to all necessary functions to update itself (since it was implemented in the constructor before, judging by the information in the OP).

But yes, good addition, maybe this callback is useful for somebody.