fusion23
22nd June 2011, 08:12
I have a custom widget I've made. It consists of a custom QPushButton and a QFrame in a vertical layout. Within the QFrame is a QWidget used as a container. Click the button to toggle the visibility of the widget inside the frame and the frame will resize. This creates a nice expanding widget. I can use this widget without problems programmatically, but I want to design in a WYSIWYG manner, so I need to create a QtDesigner plugin.
I've created a small test widget, MyWidget, that mimics the above. It has a button and a widget in a vertical layout. The plugin, mywidgetplugin returns true for isContainer(). I can see and place MyWidget inside Qt Designer and place widgets onto MyWidget. While this is cool, it's not the exact functionality I need. I need to be able to place widgets onto the container widget inside MyWidget (see attached image).
6598
Does anybody know how to expose a child widget of a custom widget via a plugin so Qt Designer can see it as a viable container?
I was hacking around and I tried this...it almost works until it crashes Designer when I click and drag the mouse over the container widget. (probably because I'm doing something stupid, but I don't know enough programming to avoid it). It also doesn't save properly because when I reopen the ui file the original container widget (with all the new checkboxes/radio buttons/etc inside) is now just a free floating child of MyWidget, and MyWidget has its own clean container widget. This probably has something to do with *child pointer and how MyWidget gets recreated when I reload the ui file, but I don't know enough to troubleshoot this.
My Widget:
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QPushButton *button = new QPushButton();
button->setObjectName("__qt__passive_button");
QWidget *containerWidget = new QWidget();
containerWidget->setObjectName("container");
layout->addWidget(button);
layout->addWidget(containerWidget);
}
Here's the hack to the plugin:
void MyWidgetPlugin::initialize(QDesignerFormEditorInte rface *formEditor)
{
if (m_initialized)
return;
// Add extension registrations, etc. here
manager = formEditor->formWindowManager();
qDebug() << manager;
m_initialized = true;
}
bool MyWidgetPlugin::isInitialized() const
{
return m_initialized;
}
QWidget *MyWidgetPlugin::createWidget(QWidget *parent)
{
QWidget *myWidget = new MyWidget(parent);
if (manager)
formWindow = manager->formWindow(0);
QWidget *child = myWidget->layout()->itemAt(1)->widget();
if (formWindow)
formWindow->manageWidget(child);
return myWidget;
}
Here is an image comparing before and after the hack. I'd like to be able to do what is in the right image legitimately if Qt Designer allows. I found this old post that seems to imply it might not be possible:
http://www.qtcentre.org/threads/16972-Container-plugins?highlight=container
Any help would be much appreciated. I would much rather setup my little widgets in a WYSIWYG fashion than by programming.
Kevin
I've created a small test widget, MyWidget, that mimics the above. It has a button and a widget in a vertical layout. The plugin, mywidgetplugin returns true for isContainer(). I can see and place MyWidget inside Qt Designer and place widgets onto MyWidget. While this is cool, it's not the exact functionality I need. I need to be able to place widgets onto the container widget inside MyWidget (see attached image).
6598
Does anybody know how to expose a child widget of a custom widget via a plugin so Qt Designer can see it as a viable container?
I was hacking around and I tried this...it almost works until it crashes Designer when I click and drag the mouse over the container widget. (probably because I'm doing something stupid, but I don't know enough programming to avoid it). It also doesn't save properly because when I reopen the ui file the original container widget (with all the new checkboxes/radio buttons/etc inside) is now just a free floating child of MyWidget, and MyWidget has its own clean container widget. This probably has something to do with *child pointer and how MyWidget gets recreated when I reload the ui file, but I don't know enough to troubleshoot this.
My Widget:
MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QPushButton *button = new QPushButton();
button->setObjectName("__qt__passive_button");
QWidget *containerWidget = new QWidget();
containerWidget->setObjectName("container");
layout->addWidget(button);
layout->addWidget(containerWidget);
}
Here's the hack to the plugin:
void MyWidgetPlugin::initialize(QDesignerFormEditorInte rface *formEditor)
{
if (m_initialized)
return;
// Add extension registrations, etc. here
manager = formEditor->formWindowManager();
qDebug() << manager;
m_initialized = true;
}
bool MyWidgetPlugin::isInitialized() const
{
return m_initialized;
}
QWidget *MyWidgetPlugin::createWidget(QWidget *parent)
{
QWidget *myWidget = new MyWidget(parent);
if (manager)
formWindow = manager->formWindow(0);
QWidget *child = myWidget->layout()->itemAt(1)->widget();
if (formWindow)
formWindow->manageWidget(child);
return myWidget;
}
Here is an image comparing before and after the hack. I'd like to be able to do what is in the right image legitimately if Qt Designer allows. I found this old post that seems to imply it might not be possible:
http://www.qtcentre.org/threads/16972-Container-plugins?highlight=container
Any help would be much appreciated. I would much rather setup my little widgets in a WYSIWYG fashion than by programming.
Kevin