View Full Version : Does a parent widget receive a method call or signal when its widgets are created or
reed
2nd September 2008, 20:43
Hello,
Is there a virtual method or a signal that a widget receives when a new widget is created or displayed that uses the first as its parent?
For example, I have widget foo, then create a new QWidget bar(foo), so foo is bar's parent. I want foo to do something to bar when bar is created or shown.
Actually, I'm specifically interested in QDialogs as children of a parent widget.
Does this make sense? Does anyone have any ideas?
Thanks
Reed
jpn
2nd September 2008, 20:46
Any QObject receives an event of type QEvent::ChildAdded when a child gets added.
reed
2nd September 2008, 22:50
Aha, this may be what I need.... will try it.
(I'm doing something slightly weird :) )
Thanks!
reed
3rd September 2008, 15:15
In the QObject docs it says
"In both cases you can only rely on the child being a QObject (or, if QObject::isWidgetType() returns true, a QWidget). This is because in the QEvent::ChildAdded case the child is not yet fully constructed; in the QEvent::ChildRemoved case it might have already been destructed."
I'm guessing this is because childAdded() is called by the child's constructor? If so, can I save a pointer to the child, and emit a signal, and then safely access the child widget in the slot for the signal (i.e. when does Qt's next process pending signals)?
jpn
3rd September 2008, 15:19
At least if you make the connection explicitly queued, then the object has been fully constructed once the slot fires.
reed
3rd September 2008, 15:23
And, should I use installEventFilter() instead of overriding the childEvent() method in my class?
reed
3rd September 2008, 15:27
At least if you make the connection explicitly queued, then the object has been fully constructed once the slot fires.
::going off to read about queued connections::
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.