Designer plugin widget: how to achieve different look in preview than in design view?
-
I am building some Qt Designer plugins for some widgets that I have created. One widget is basically acting like a spacer, so it should be non-visible at runtime. However, it would be nice if I could make it draw something for display at design time, to make it easier to handle. Basically, it should look a bit like the spacers do in design view. The actual drawing isn't that hard, but I can not find a way to distinguish if my widget is created for use design view or for use in preview. It seems in both cases, the plugins' createWidget() method is called, and there are no parameters there I can use for this it seems. Any suggestions, tips or tricks to get around this?
-
Hmmm... OK, one solution (bit of a hack, but ok) is to use this implementation of the createWidget() method:
@
QWidget *CheckBoxSpacerWidgetPlugin::createWidget(QWidget parent)
{
MyWidget resultWidget = new MyWidget(parent);QWidget* pw = parent; while (pw) { qDebug() << "parent class:" << pw->metaObject()->className() << pw->inherits("QDesignerWidget"); if (pw->inherits("QDesignerWidget") ) { //this one seems to be only used in Design mode-- //the m_inDesignerModeFlag is private in the widget, but the plugin is a friend class of the widget resultWidget->m_inDesignerModeFlag = true; break; } pw = pw->parentWidget(); } return resultWidget;
}
@