in your example everything is covered within one single function
refering to each button by its name ("1") ("2") etc
My function doesn't refer to each button's name, but instead to the argument that each button passes into the function via the connected signal.
Regarding the other specific questions about managing the entered information... Certainly, anything that's completely defined and logical can be done via code. Before starting down that path though, you should fully define how the control should work. That definition should cover all possible situations.
Without a complete definition of the problem, you (or me, or someone else) will end up creating code that works for the current definition, but isn't easy to extend to cover that one thing you forgot to mention...
Based on the questions you're asking, I'd think the best general approach would be to manage the string itself completely independently of the visible GUI components. That is, just edit (add, remove chars) from a string variable while applying your rules (whatever those are - comma handling, number of char handling, ...).
With the string properly managed, you could then secondarily take the contents of that string and render into your on-screen controls - again, using whatever rules you've defined (splitting pieces between various labels, ...)
So, a method that does something like:
- Accepts the next char (either an addition or deletion)
- Modifies the string accordingly (including enforcing your rules of correctness)
- Inserts the resulting string into the on-screen GUI (again, according to your rules)
Again, the hardest part is probably fully and accurately defining how it should work.
Additionally, I think it's important that all character handling passes through the same, single function for processing. Trying to maintain a complex rule set in a bunch of independent functions will be a maintenance nightmare and will be very prone to errors.