Can a widget be notified if it's parent changed?
-
wrote on 10 Mar 2023, 11:52 last edited by bibasmall 3 Oct 2023, 12:06
Hi all!
I have several dock widgets in my project, all of which contain widgets that are subclasses of the same base class (this class is QWidget subclass). In this base class, I want to implement layout margins recalculation in case the parent widget is a dock widget and the dock area has been changed (via a connection toQDockWidget
signal). The point is my class knows nothing about a dock widget wrapper and it needs to be notified that the parent is changed when it's put inside a dock widget to create a connection.
There is an ugly way to achieve my needs by calling something likeMyBaseClass::DockParentSet
every time afterQDockWidget::setWidget
and create a connection in this function, but I would prefer to encapsulate this detail if possible.
Is there an elegant way to notify a widget if its parent has changed? -
wrote on 10 Mar 2023, 12:29 last edited by
I was looking for
bool MyBaseClass::event(QEvent* e) { if (e->type() == QEvent::DynamicPropertyChange && qobject_cast<QDockWidget*>(parent())) //... }
-
2/2