PDA

View Full Version : How to decide whether to make a separate class for widgets of a window?



TheIndependentAquarius
15th February 2012, 06:34
The main window contains a:


TODO list (text box), time allotted (list box), start time (text box).
Count down timer (timer), start button (button).


I already have a class for the timer which contains few slots too.

Remaining widgets have their objects declared in the main() currently.

Now, I need to get the clicked item from the list and supply it to the timer.
The way to do it is to create signal-slots.

How to decide whether to make a separate class for widgets of a window or club them all together?

Any design patterns here?

Does MVP has anything to do with this "current case"?

Lykurg
15th February 2012, 07:02
The decision is up to you. I personally would go for separate classes, because they are better manageable and maintainable. Then only do a "container" widget which layouts the custom widgets and do the signal and slot connections.

If you mean model and view programming with MVP, then it has nothing to do with your question.

TheIndependentAquarius
15th February 2012, 07:26
Then only do a "container" widget which layouts the custom widgets
What did you mean here, I didn't understand well. Please explain again.

Lykurg
15th February 2012, 07:41
E.g. you have custom widgets A, B, C, and D which should have connections. Then make a QWidget W and in its constructor initiate ABCD, arrange them using e.g. QGridLayout and connect the signals and slots between ABCD.

This way you only have to initiate W whenever you need ABCD inside your application.

TheIndependentAquarius
15th February 2012, 07:51
Thanks.
If I face some more problems I'll post back.