[Qt-interest] Generic input widgets for varying types - how to?

Helge Preuss helge.preuss at gmx.net
Fri Mar 27 22:57:57 CET 2009


Andreas Pakulat wrote:
> Right, thats why I said you should just write the gui-creation code
> yourself instead of "pretending" to use designer/uic when you actually
> don't really do it.
>   
Ok :-).
>>> So you could just do
>>> QWidget* inputWigdet = Factory::create( LineEdit );
>>> dynamic_cast<ParameterInput*>(inputWidget)->setValue( "SomeString" );
>>>
>>> Or even pass around the "widget" only by using the ParameterInput
>>> pointer so no code outside the place that actually creates the widgets
>>> from the factory sees which widget is behind the ParameterInput.
>>>   
>>>       
>> I'm not quite sure whether this is possible for me, but I'll give your
>> idea a test ride.
>>     
>
> Well, wether its possible or not simply depends on what you're designing
> this interface for, i.e. whats the intended use for it. So far my
> understanding was that code that uses that interface simply shouldn't
> care how the data it supplies is visualized, 
That's correct.
> in which case it would make
> perfect sense to only pass around a pointer to the interface and not a
> QWidget* which would then possibly be casted down to the actual
> widget...
>   
It appears that this is actually the case. Nice!
>> It's not the /whole/ QLineEdit interface (the ParameterInput interface
>> just contains get/setValue()), but apparently those parts that make the
>> QLineEdit displayable correctly (that is kind of what question 2 in my
>> original post was aiming at - which functions would that be?). But your
>> point is taken.
>>     
>
> Well, you'd need to replicate most, possibly all of the public+protected
> API in QWidget to make it display and behave properly (especially all
> the event handlers).
>   
That would depend on which functions are needed to "behave properly". In
particular, because the user must click on an "Accept"-button to commit
any changes made, I don't think the event handlers would be needed. But
as long as I don't actually use composition and delegation this
discussion is purely academic.

Greets,

Helge

-- 
Helge Preuss
Freelance Software Developer
+49 30 40 30 10 90
+49 177 2262 484
helge.preuss at gmx.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090327/81059707/attachment.html 


More information about the Qt-interest-old mailing list