PDA

View Full Version : Custom plugin for a layout



cocheci
12th June 2006, 18:00
Is it possible to create a designer plugin for a custom "widget" that does not derive from QWidget? I have a custom layout class that derives from QBoxLayout, and I would like to display it in designer, just like I do with my custom widgets. The problem is that the createWidget() method of the plugin class returns a QWidget*, but the layout does not derive from QWidget.

Thanks,
Cristian

wysota
12th June 2006, 18:53
Is it possible to create a designer plugin for a custom "widget" that does not derive from QWidget? I have a custom layout class that derives from QBoxLayout, and I would like to display it in designer, just like I do with my custom widgets. The problem is that the createWidget() method of the plugin class returns a QWidget*, but the layout does not derive from QWidget.


No, it has to be QWidget. You can cheat a little though and return an empty QWidget just with your layout set (just remember the widget has to be marked as a container).

I don't remember the exact syntax, but it's something like this:

QWidget * plugin::createWidget(const QString &feature, QWidget *p){
if(feature=="xxx"){
QWidget *w = new QWidget(p);
MyLayout *l = new MyLayout(p);
w->setLayout(l);
return w;
}
}

cocheci
12th June 2006, 19:36
No, it has to be QWidget. You can cheat a little though and return an empty QWidget just with your layout set (just remember the widget has to be marked as a container).

I don't remember the exact syntax, but it's something like this:

QWidget * plugin::createWidget(const QString &feature, QWidget *p){
if(feature=="xxx"){
QWidget *w = new QWidget(p);
MyLayout *l = new MyLayout(p);
w->setLayout(l);
return w;
}
}


This worked, thank you!
Cristian