[Qt-interest] Same widget in two Designer plugins - problem
André Somers
andre at familiesomers.nl
Fri Sep 30 15:14:35 CEST 2011
Thanks a lot for your suggestion.
One question remains: if I return a different class name in the XML, what
will actually be generated by uic?
It sounds like you are suggesting that, just for the sake of Designer
integration, I actually subclass my Slider class and create VSlider and a
HSlider, that do nothing else than set the right orientation by default?
That seems taking it a bit far, for me. I guess it would work, but it is not
the way it seems to be done with QSlider. That one actually generates a
QSlider as the class name (not matching the name I see in designer!) I would
like to avoid having to subclass the actual widget (even if that is very
simple) just for the sake of Designer integration, especially since these
subclasses will end up in the generated code.
I really don't get why the name() from the plugin needs to match the class
from the domXml(). If the information is supposed to be the same, then I
only want to supply it once. If it is supposed to be different, then I
should be allowed to have them different...
Andre
On Fri, Sep 30, 2011 at 2:44 PM, Frank Hemer <frank at hemer.org> wrote:
> On Friday 30 September 2011 14:32:25 André Somers wrote:
> > Hi,
> >
> > I have created my own slider widget. I have also developed a designer
> > plugin for it. That all works nicely. However, as soon as I want to
> mimick
> > the behaviour of the way QSlider is integrated into designer, I run into
> > problems. I would like to have a separate vertical and horizontal slider
> > item in the list of widgets, but I can not figure out how to do that. If
> I
> > put another name than the actual class name in the name()
> reimplementation,
> > I get complaints from designer and I do not get a visual widget if I drag
> &
> > drop the widget to a form. However, if I use the same name (and just a
> > different description and icon), I get into other problems: only one of
> the
> > sliders is showing.
> >
> > Am I missing something here? How do the standard widgets manage to use
> > human readable names (not the class name) for their widgets without
> issue?
> > Why can QSlider appear twice, but own slider not?
>
> You need to have individual implementation classes for the two slider types
> thus you can write in the createWidget reimpl:
>
> QWidget * SSliderPlugin::createWidget (QWidget * parent) {
> if (m_orientation == Qt::Horizontal) {
> return new SHorizontalSlider (parent);
> } else {
> return new SVerticalSlider (parent);
> }
> }
>
> and in name:
>
> QString SSliderPlugin::name () const {// very important to be created in
> designer
> if (m_orientation == Qt::Horizontal) {
> return QLatin1String("SHorizontalSlider");
> } else {
> return QLatin1String("SVerticalSlider");
> }
> }
>
> and in domXml:
>
> QString SSliderPlugin::domXml () const {// very important to be created in
> designer; note the class and name info!!!
> QString xml ("<widget class=\"%1\" name=\"sSlider\">\n"
> "</widget>\n");
> return xml.arg (m_orientation ==
> Qt::Horizontal ? "SHorizontalSlider" : "SVerticalSlider");
> }
>
> and when registering the plugins:
>
> m_plugins.append (new SSliderPlugin (this, Qt::Horizontal));
> m_plugins.append (new SSliderPlugin (this, Qt::Vertical));
>
> To have two impl classes for one plugin, thats easy:
>
> class SHorizontalSlider : public SSlider {
> Q_OBJECT
>
> public:
> SHorizontalSlider (QWidget * parent = 0)
> : SSlider (Qt::Horizontal, parent) {}
> virtual ~SHorizontalSlider () {}
> };
>
> class SVerticalSlider : public SSlider {
> Q_OBJECT
>
> public:
> SVerticalSlider (QWidget * parent = 0)
> : SSlider (Qt::Vertical, parent) {}
> virtual ~SVerticalSlider () {}
> };
>
> Note: code above is untested -
>
> Have fun
> Frank
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110930/36171622/attachment.html
More information about the Qt-interest-old
mailing list