176 views
in GUI Development by
Hi,

I've got this problem, I need to adding dinamically new Buttons in a GUI. (dinamically because it is my Device that own the number of PushButton that I neew to include in the GUI).

So in the GUI that I'm developping I have inserted an Array of Application::CustomPushButton of 16 items (null items) (16 items is based on the max of possible PushButtons that I can have on the GUI).

In the Init method and with other method I communicate with the Device and I fill the Array with this command:  this.ArrayofButtonLingue[x] = new Application::PushButtonGraficoTemplates; finally with a for statement I use your method Add() to add the buttons on the GUI, and I link the OnRelease property of all with the correct slot "slotOnRelease" that I have created.

The above steps works fine, and I can see the buttons on my GUI, the problem now is this: when I press and release one Buttons I don't know ho to recognize the one that has been released with the keyword "sender. If I try to trace the sender I have got for example these name:

trace: (WidgetSet::PushButton)0x3FA74FF0

or trace: (WidgetSet::PushButton)0x3FA6E484

and so on.

 

So I have 2 questions:

1) is it possible to recognize the sender of the slot method to implement the proper callback.

2) Is it the add() method the correct one to do this kind of funcionality: "Dinamically adding new buttons on the GUI" ? Or is there another way to do so ( I have choose the Add() method to save memory on the device and avoid to add static buttons and disabling one by one with a for statement)

1 Answer

0 votes
by

Hallo Emanuele,

in your application case you want to create buttons dynamically. The buttons have then to be connected to concrete (not dynamic surely) operations. The approach with comparing sender will not work in this case, because the buttons are created dynamically and their addresses are not known unless you save the addresses of the buttons in variables and use the variables then.

What I would do? Besides many other options I would propose the following both:

Option 1: Even when you create the buttons dynamically, the operations the buttons are associated to are predetermined. You could thus implement for each operation a separate slot method and when creating a button dynamically associate the button with the desired slot method directly. Evaluating sender is not needed anymore.

Option 2: Obviously you have implemented the push button in your own component Application::PushButtonGraficoTemplates. You can enhance this component by some additional property named e.g. Tag or Id, etc. When you create a push button dynamically, you initialize the new property with a value corresponding to the operation of the button. Within the slot method associated to all buttons you can then evaluate the value stored in the buttons activated by user as shown below:

var Application::PushButtonGraficoTemplates button = (Application::PushButtonGraficoTemplates)sender:

if ( button != null )
  switch ( button.Tag )
  {
    case 1 : /* button with Tag == 1 pressed */;
    case 2 : /* button with Tag == 2 pressed */;

    ... 
  }

Does it help you further?

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...