How to create a plugin for QtDesigner?
-
I want to create a custom widget that appears in the toolbar of QtDesigner... I already have this:
#include <QtUiPlugin/QDesignerCustomWidgetInterface> class QtCustomChartPlugin : public QObject, public QDesignerCustomWidgetInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface" FILE "qtcustomchartplugin.json") Q_INTERFACES(QDesignerCustomWidgetInterface) public: QtCustomChartPlugin(QObject *parent = nullptr); bool isContainer() const; bool isInitialized() const; QIcon icon() const; QString domXml() const; QString group() const; QString includeFile() const; QString name() const; QString toolTip() const; QString whatsThis() const; QWidget *createWidget(QWidget *parent); void initialize(QDesignerFormEditorInterface *core); private: bool initialized; };
But when using the custom plugin the header file is not found???
Regards,
Juan Dent -
@jdent said in How to create a plugin for QtDesigner?:
the header file is not found???
Which header file? The one you posted or this:
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
If the latter,
UiPlugin
isn't found and linked in CMake. Every step is deocumented here. -
@jdent said in How to create a plugin for QtDesigner?:
But when using the custom plugin the header file is not found???
Do you use CMake or QMake?
For QMake there is this example in the documentation:
CONFIG += plugin TEMPLATE = lib QT += widgets uiplugin
-
I added the path to qtcustomchart.h to my include path and now I get
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QtCustomChart::QtCustomChart(class QWidget *)"
There is this file dll_exporting.h that contains:
#pragma once #include <QtCore/qglobal.h> #ifndef BUILD_STATIC # if defined(QTDESIGNERWIDGET1) # define QTDESIGNERWIDGET1_EXPORT Q_DECL_EXPORT # else # define QTDESIGNERWIDGET1_EXPORT Q_DECL_IMPORT # endif #else # define QTCLASSLIBRARY1_EXPORT #endif
So I undefined QTDESIGNERWIDGET1
to no avail .... error persists!
-
@jdent said in How to create a plugin for QtDesigner?:
The header that is not found is:
#include "qtcustomchart.h"
I asked before whether you are using QMake or CMake.
Either you exported your plugin wrong or you've built / linked it wrong.
Therefore show your.pro
file or CMake file please :)Is your plugin + plugin interface built like this example?
-
So the plugin is showing up in the designer and you can use it like other widgets to create your ui file or not? Please be more precisie when you get what error.
If so and you only get linker errors when compiling your application you forgot to link against the actual library which contains your custom widget. -
@Christian-Ehrlicher yes the Designer inside VS2022 displays the custom chart and inserts the header file in the ui file. However, it does not automatically add its path to the include path of the project nor does it add the import lib in the linker
I had to do this by hand
Is there a way to automate this process? for example, the ideal would be I choose a custom plugin in Qt Designer and upon saving it the header file is not only added to the ui generated file but the include path and linker paths are updated as well. Is this possible? -
@jdent said in How to create a plugin for QtDesigner?:
I had to do this by hand
That's the way it is - you also have to link against QtWidgets by hand even you put a widget in your ui file from the widgets library. There is no way a designer plugin can modify the build system.