[Kde-bindings] QWidgetFactory in ruby

Richard Dale Richard_Dale at tipitina.demon.co.uk
Wed Apr 14 13:16:21 UTC 2004


On Wednesday 14 April 2004 13:38, ian reinhart geiser wrote:
> Richard Dale said:
> > [22:56:19] <taj> QWidgetFactory sucks!
> > [22:56:53] <taj> AFAIK you can't get widget metadata without actually
> > instantiating the UI
> > [22:57:17]  taj agrees that parsing the UI is a much better solution in
> > the
> > medium term
> > [22:59:24]  taj would be very happy to be proven wrong though
> > [23:03:45]  taj is working on an import hook for python that allows you
>
> its up to you.  it works quite well in kjsembed.  we extract all metadata
> before show is called.  The widget is created as in allocated, but is
> still hidden.  how do you think the ui file icon preview works ;)
>
> but its your choice... personally i hate writing code for the heck of it.
>
> i do have something similar to the dcopref code in pydcop on the way for
> UI files... maby this is what taj is talking about not sure.  its not very
> hard, its actually harder to get the damn objects created in python than
> to extract the metadata.
I think I might have worked out how to do it. From the 
QWidgetFactory::createWidget() documentation:

"If you have a custom widget, and want it to be created using the widget 
factory, there are two approaches you can use: 
...

Subclass QWidgetFactory. Then reimplement this function to create and return 
an instance of your custom widget if className equals the name of your 
widget, otherwise return 0. Then at the beginning of your program where you 
want to use the widget factory to create widgets do a: 
    QWidgetFactory::addWidgetFactory( new MyWidgetFactory );
    
 where MyWidgetFactory is your QWidgetFactory subclass. "

I think I could create a subclass of QWidgetFactory called RubyWidgetFactory 
and override the createWidget() method. But instead of using 
'addWidgetFactory( new RubyWidget Factory )' as above it would just treat 
RubyWidgetFactory as the main factory. 

Otherwise, all the Qt widgets are hard wired into the standard QWidgetFactory, 
and you aren't expected to use custom widget factories to instantiate them in 
a different way. So RubyWidgetFactory::createWidget() would need to know how 
to create all the Qt widgets as well as the KDE ones.

-- Richard



More information about the Kde-bindings mailing list