PDA

View Full Version : extend funcitionality of Designer widgets



dexli
30th March 2011, 16:23
Hi all,

after I setup a gui with Qt designer I want to add a method to some of the used widget.

eg.
having a QListWidget StList to which I want to add a filter. The filter will be selected from a QComboBox state.

I think the "normal" aproach would be to create a new class myListWidget which base class is QListWidget and implemet a slot FilterChange which act accordingly.

But if i do so I have no benefit from the designer as long I do not provide a plugin for this widget. To write a plugin for onetime use seems not to be a clever appoach.



So what to do ??

Thanks
dexli

stampede
30th March 2011, 17:49
But if i do so I have no benefit from the designer as long I do not provide a plugin for this widget.
You'll have the benefit - you can visualize the layout of your widgets. That's why I'm using the designer - application logic should be separated from the application's look - I use designer to design the user interface, the way application should look, not how it should behave.
If you feel that you can reuse your QListWidget subclass in the future, then why not creating a plugin.

after I setup a gui with Qt designer I want to add a method to some of the used widget.
After I setup a gui with Qt designer, I switch to code editor in order to implement the functionality ( add methods to some of the used widgets ).

SixDegrees
30th March 2011, 18:33
Or, you can perform the inheritance step offline, then use Designer's promotion feature to include your custom widget in the layout. It won't display any custom functionality like signals or slots you might have implemented, but it'll appear in the layout and the generated code will use the correct class.

dexli
31st March 2011, 10:05
Hi,
sorry maybe I don't make things clear enough.

As far as I understud if I setup a new class which inherit from a widget class I have to write a plugin for designer to use this class in the designer. This is only efficient if you reuse this class serveral times. (not ony onetime)


After I setup a gui with Qt designer, I switch to code editor in order to implement the functionality ( add methods to some of the used widgets ).


And if you have to change the layout all the work is gone because this file is overwritten by the designer. So that seem not to be a good choice to me.


Or, you can perform the inheritance step offline, then use Designer's promotion feature to include your custom widget in the layout. It won't display any custom functionality like signals or slots you might have implemented, but it'll appear in the layout and the generated code will use the correct class.

That sounds like it is what i'm looking for. :o Can you please tell me where I find a howto about this promotion feature.

Thanks

dexli

wysota
31st March 2011, 10:33
Place a base class for your widget on the form and invoke the context menu on it.

dexli
31st March 2011, 11:21
Place a base class for your widget on the form and invoke the context menu on it.

Thanks a lot.

How can I mark this thread as solved ?

stampede
31st March 2011, 12:41
And if you have to change the layout all the work is gone because this file is overwritten by the designer
Nothing is gone, because designer form is used only to manage layout, not behavior of widgets. If you want to change the layout, you just have to edit .ui file, implementation for the class (.cpp / .h ) is left untouched, only ui_*.h is automatically generated, but I don't think anyone edits this file by hand. Right click and "Promote to..." is what you are looking for.

wysota
31st March 2011, 12:47
but I don't think anyone edits this file by hand
Unfortunately lots of people do it.