Skip to main content
Emilmart
Associate III
April 7, 2021
Solved

Get each items in a container and change item attribute

  • April 7, 2021
  • 3 replies
  • 1377 views

Hi,

I have some flexbuttons in a container.

I'd like to change let's say the border size of all flexbuttons inside that container when one flexbutton is pressed.

Is there a way to do it with some kind of foreach loop ? like: for each item in the container, if the item is a flexbutton, item.changeBorderSize(10);

thanks!

Best answer by Michael K

I remember looking into this a while ago but I gave up and just created an array of pointers to each widget I wanted to iterate through, with the reasoning that I know my objects at compile-time anyway. These container methods may be useful to you if you still want to try and iterate through the container. Would be interested to know if anyone has accomplished what you described.

3 replies

Michael K
Michael KBest answer
Senior III
April 7, 2021

I remember looking into this a while ago but I gave up and just created an array of pointers to each widget I wanted to iterate through, with the reasoning that I know my objects at compile-time anyway. These container methods may be useful to you if you still want to try and iterate through the container. Would be interested to know if anyone has accomplished what you described.

Emilmart
EmilmartAuthor
Associate III
April 8, 2021

thanks for the workaround!

ferro
Lead
March 1, 2023

Hi,

Step 1

class DoThisToEveryChild : public GenericCallback< Drawable & >
{
	virtual void execute ( Drawable & d ) final
	{
		// user code here e.g.
		// d.setVisible ( false );
	}
	
	virtual bool isValid () const final
	{
		return true;
	}
};

Step 2

DoThisToEveryChild doThis {};
 
// now 'DoThisToEveryChild::execute ()' will be called for every child in 'ticks' container
ticks.forEachChild ( & doThis );

Associate III
December 19, 2024

This is the correct way to iterate through container or screen elements

void Task_Stopped::handleClickEvent(const ClickEvent &evt)
{
 Drawable *d = getFirstChild();
 while (d)
 {
 d->handleClickEvent(evt);
 d = d->getNextSibling();
 }
}