[Qt-interest] Setting default attributes for all created widgets

Andre Somers andre at familiesomers.nl
Wed Oct 6 07:42:17 CEST 2010


  Op 5-10-2010 20:06, Jake Colman schreef:
> I need to ensure that all widgets created by my application are created
> with a specific Qt::WidgetAttribute.  Obviously, that's easy enough to
> do for widgets that I explicitly create.  But I need to do this as well
> to, for example, Qt Dialogs that are created by Qt via static methods.
> Is there a way to hook into widget creation so that I get an opportunity
> to invoke setAttribute() on the widget even if it's not my code that did
> the creation?  Or is there a low-level way to tell Qt that all created
> widgets should have a specific attribute?
Interesting question! Perhaps you can create an application wide event 
filter to listen for QChildEvents. Test if the child is a widget (using 
QObject::isWidgetType) and if so, set the required attribute. I am not 
sure it will catch new windows (there should be some way to catch those, 
I guess), but it should catch all child widgets created.
There may be other ways; this is just a first idea, not a definitive answer.

André





More information about the Qt-interest-old mailing list