Custom widget works well until closing and reopening QtCreator
-
Hi everyone,
I made a custom widget plugin for QtDesigner inherited from QAbstractButton.
The plugin load well and I am able to drag and drop it into my UI as shown on picture below.My issue append when I save my .ui, I am closing QtCreator and then, when I am launching QtCreator and reopen my .ui in my project, the widget seems like it have lost its properties and the properties inherited from QAbstractButton. However when I drag and drop an other instance of the widget it seems to load properly until I repeat the procedure (Closing QtCreator and reopening it and project). Picture below to see what appen after closing QtCreator and reopening project.
When I am compiling and launching generated app, the widget works well.
I feel like issue comes from domXml method but I am not sure and all my try were unsuccessfull.
Here are the plugin source code :
MyWidgetPlugin.h
#ifndef TOGGLEBUTTONPLUGIN #define TOGGLEBUTTONPLUGIN #include <QtUiPlugin/QDesignerCustomWidgetInterface> class ToggleButtonplugin : public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_INTERFACES(QDesignerCustomWidgetInterface) #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) Q_PLUGIN_METADATA(IID "com.Qt.CustomWidgets") #endif public: ToggleButtonplugin(QObject* pParent = Q_NULLPTR); QString name() const override; QString group() const override; QString toolTip() const override; QString whatsThis() const override; QString includeFile() const override; QIcon icon() const override; bool isInitialized() const override; bool isContainer() const override; QString domXml(void) const override; QWidget *createWidget(QWidget *parent) override; private: bool initialized; }; #endif // TOGGLEBUTTONPLUGIN
MyWidgetPlugin.cpp
#include "togglebuttonplugin.h" #include "togglebuttonwidget.h" #include <QtPlugin> ToggleButtonplugin::ToggleButtonplugin(QObject* pParent) : QObject(pParent), initialized(true) {} QString ToggleButtonplugin::name() const { return "ToggleButton"; } QString ToggleButtonplugin::group() const { return tr("PSR Custom Widgets"); } QString ToggleButtonplugin::toolTip() const { return tr(""); } QString ToggleButtonplugin::whatsThis() const { return tr(""); } QString ToggleButtonplugin::includeFile() const { return "togglebuttonwidget.h"; } QIcon ToggleButtonplugin::icon() const { return QIcon(":/icon/checked"); } bool ToggleButtonplugin::isContainer() const { return false; } QString ToggleButtonplugin::domXml(void) const { return QLatin1String("<ui language=\"c++\"><widget class=\"ToggleButton\" name=\"togglebutton\"/>\n<customwidgets>\n<customwidget><class>ToggleButtonWidget</class>\n<extends>QAbstractButton</extends>\n</customwidget>\n</customwidgets>\n</ui>"); } bool ToggleButtonplugin::isInitialized() const { return initialized; } QWidget * ToggleButtonplugin::createWidget(QWidget *parent) { return new ToggleButtonWidget(parent); } #if QT_VERSION < QT_VERSION_CHECK(5,0,0) Q_EXPORT_PLUGIN2(togglebuttonplugin, ToggleButtonPlugin) #endif
Config :
Windows 10
Qt 5.15.1
QtCreator 4.14.1
Compilator : MSVC/MinGW same issuesAny help would be welcome. Thanks