[Qt-interest] Generic input widgets for varying types - how to?
Helge Preuss
helge.preuss at gmx.net
Fri Mar 27 21:03:25 CET 2009
Andreas Pakulat wrote:
> On 27.03.09 20:18:05, Helge Preuss wrote:
>
>> Question 1:
>> Is this a good way to do it? Differently put, is there a /better/ way
>> ;-) ? In particular, I am a bit concerned about deriving the concrete
>> input widgets from QWidget twice - once via ParameterInput and once via
>> QSlider/QLineEdit.
>>
>
> Thats not supported by Qt, you can only derive from QObject once. So
> make the input class a pure interface and inherit first from the gui
> widgets.
>
Uh-oh. How would I make a dialog contain a ParameterInput then? It must
be a QWidget, else it cannot be a sub-widget, am I right?
>
>
>> Question 2:
>> This does not really work. The ParameterInput widgets are not displayed.
>> I assume I must implement some QWidget methods to make the widgets
>> display. Which methods would that be?
>>
>
> I suggest to fix the above first and then revisit this, all kinds of
> weird things may happen when you subclass twice from qwidget. In
> particular in your case probably the paintEvent of QWidget is being
> called (just painting a grey background) instead of the one from the
> actual widgets.
>
That's probably what happens, yes.
So if my above hunch about ParameterInput having to be a QWidget is
correct, I'll probably have to use composition in the derived classes.
Such as:
class ParameterLineEdit: public ParameterInput {
private:
QLineEdit *delegateLineEdit;
void setValue(const QString &s) { delegateLineEdit->setText(s); }
// etc.
}
Would that work? (I'm making this up as I write, haven't thought this
through.)
Thanks,
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/553d5922/attachment.html
More information about the Qt-interest-old
mailing list