How to handle interaction between widgets?

Added by Kirill Brutyev 11 months ago

Hi I'm new to WT. I'm trying to understand what is a good practice.

Suppose I have a grid layout and I have two widgets in different cells: widget A and widget B. They both have separate classes: WidgetA and WidgetB.
I want to be able to click a button in a widget A and make widget B hide.
One way I can think of doing it is to pass a pointer of widget B to widget A. Another is to have a class C that is kind of a singleton and handles all the passing.
What stopped me is that in examples I don't see too many passes of pointers to widgets. All of the interaction happens within the same class.

I think i'm missing something.
Can someone point me to an example like that or tell me which design pattern is used?

I"m really impressed with WT so far. thank you.
Best,
--Kirill


Replies (1)

RE: How to handle interaction between widgets? - Added by Koen Deforche 11 months ago

Hey,

This a fair question.

Ideally you want to minimize dependencies between widgets, and Widgets should mostly know only about widgets they contain.

If you use an overall layout you can't do that (which might be not the optimal choice if you can avoid it).

In any case you should use signals to a avoid dependencies which has the additional benefit of a avoiding dangling pointers.

Regards,
Koen

(1-1/1)