PDA

View Full Version : Button Grouping for generic functions



hojoff79
7th January 2011, 13:46
I am trying to create a class or some sort of setup that groups several groups buttons so that I can create one function that will apply to all the groups. Then I can hopefully use a this call to change the other buttons in the class and/or grouping.

For example, say I have a setup of 3 buttons, for example Start, Add, and Subtract. I want to set up several instances of this three button grouping on one main window, say 5 instances. Each instance starts with the Add and Subtract buttons not enabled. I want a way to create one function start() which will be called when any one of the start buttons is pushed, and the function will enable the Add and Subtract button in that grouping and disable the start button that is clicked.

The only way I know how to do it now is to create 5 different functions, one for each instance of the three buttons, which has basically the same code but with each of the different functions referring to a different set of buttons.


So how can I create a grouping so that I only need one function to handle all of the groupings (my actual program has more than 5 instances with several functions for each instance, so figuring out this general procedure will significantly decrease the amount and cleanliness of my code).

Thank you in advance.

wysota
7th January 2011, 13:54
Create a custom widget composed of your three buttons and add a start() slot to the widget that will change the enabled state of the buttons in the widget. Also add two or three signals emitted when a particular button in the group is clicked.