cancel
Showing results for 
Search instead for 
Did you mean: 

Setting RadioButton state without triggering action.

franck23
Senior

Hi,

I have 3 radio-buttons in a custom container which is present on several screens.

I would like the radio-buttons to keep their states between when switching screens.

I have the radio-buttons states reported to the model every time a button is pressed and when the screen changes, the new active view fetches the radio-button state.

However, I do not see a function to update a radio-button state without triggering the button action.

Is there such a function?

12 REPLIES 12
MM..1
Chief II

void Screen1View::setupScreen()
{
    Screen1ViewBase::setupScreen();
 
    radioButtonGroup1.setSelected(radioButton1);
 
}

 maybe better is create array for objects radio and store index, because call need pointer to object.

franck23
Senior

Thanks, but the problem with setSelected is that it triggers the button action: the radioButtonSelectedCallbackHandler is called.

I am looking for a way to set the radio buttons without triggering the callback Handler.

If there is no way to do it directly, I will set a flag to ignore the callback.

franck23
Senior

Also, when using radioButtonGroup1.setSelected(radioButton1), the radioButtonSelectedCallbackHandler get called twice.

I haven't been able to trace what is triggering the second call but this looks like a bug.

Hi,

What you could do is modify the setSelected function in RadioButton.cpp file in the Middlewares folder or create another function to handle this situation.

/Romain

Interesting, I will investigate. Could you share a project where this happens ?

/Romain

franck23
Senior

Hi Romain, thanks for looking into it.

I do have a sample project to demonstrate the issue, but it looks like the forum file attachment feature is disabled.

The attachment icon next to the picture icon is greyed out.

Or maybe I am looking at the wrong place?

BTW, is there another way to keep the custom container synchronized between screens?

Most of the time, it makes sense for the widgets to stay in the same state between screens.

Yes is i mean called twice for button 2 and 3 , when select 1, because this need be deselect...

Try don’t use group and instead for loop for all radioButton with direct set select/deselect.

It is the "Selected" callback of the button1 which is being called twice, I am not checking the "Deselect" of button2 and 3.

The setSelected feature of the radioButton will trigger the button Select callback too (and it is flagged as not recommanded for radiobuttons).

/**
     * Sets the radio buttons selected state. Note that the associated action is also
     * performed.
     *
     * @param  newSelected The new selected state.
     *
     * @see setAction, setDeselectedAction, RadioButtonGroup
     *
     * @note If the RadioButton is part of a RadioButtonGroup, setting the selected state of
     *       individual RadioButtons is not recommended.
     */
    void setSelected(bool newSelected);

franck23
Senior

@Romain DIELEMAN​ 

OK, just found the attachment icon...

The attached project is derivated from the TouchGFX Designer RadioButton Example.

It was tested with the simulator and on a discovery board with the same results.

There is a counter which is incremented every time the radioButton2Selected() get called.

Clicking on button1 execute radioButtonGroup.setSelected(radioButton2);

If radiobutton2 is clicked, the counter increments by 1 (normal behavior)

If button1 is clicked, radioButton2Selected() gets called twice, and the counter increments by 2 (I would expect only one callback).