Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Is it OK to implement the Decorator design pattern using QWidget.
EmoBemo last edited by
I have a widget which displays some controls in it. I need to draw graphics on top of all other controls. For that purpose I have created Decorator subclassing QWidget and have added it to the controls widget as a child filling the whole parent's rect. The Decorator has transparent background and is transparent for mouse events. The Decorator is used to paint some graphics according to the parent's content. Is thare any possible performance disadvantages using this approach? Will there be any problem if there are mode Decorators on top of each other?
The only thing that doesn't sound right is that the decorator accesses the parent, it should rather be given the widget it should "paint over". As for the performance part it will depend on what your decorator does so you have to do some benchmarking.
If you might have several decorators on top of each other, you should maybe separate the "widget" part and the painting part so you would only have one decorator but you can configure it to paint several overlays.
Hope it helps