Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a plugin for QtDesigner?
QtWS25 Last Chance

How to create a plugin for QtDesigner?

Scheduled Pinned Locked Moved Unsolved General and Desktop
custom pluginqt designer
9 Posts 4 Posters 514 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jdent
    wrote on 8 Sept 2024, 16:22 last edited by
    #1

    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

    A P 2 Replies Last reply 8 Sept 2024, 17:07
    0
    • J jdent
      8 Sept 2024, 16:22

      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

      A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 8 Sept 2024, 17:07 last edited by Axel Spoerl 9 Aug 2024, 17:15
      #2

      @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.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • J jdent
        8 Sept 2024, 16:22

        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

        P Offline
        P Offline
        Pl45m4
        wrote on 8 Sept 2024, 17:12 last edited by
        #3

        @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
        

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        1
        • J Offline
          J Offline
          jdent
          wrote on 9 Sept 2024, 00:20 last edited by
          #4

          I use Visual Studio 2022 tools for Qt.
          The header that is not found is:

          #include "qtcustomchart.h"
          

          This is the include that defines the custom chart.

          What am I missing?

          P 1 Reply Last reply 9 Sept 2024, 04:43
          0
          • J Offline
            J Offline
            jdent
            wrote on 9 Sept 2024, 00:30 last edited by
            #5

            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!

            1 Reply Last reply
            0
            • J jdent
              9 Sept 2024, 00:20

              I use Visual Studio 2022 tools for Qt.
              The header that is not found is:

              #include "qtcustomchart.h"
              

              This is the include that defines the custom chart.

              What am I missing?

              P Offline
              P Offline
              Pl45m4
              wrote on 9 Sept 2024, 04:43 last edited by Pl45m4 9 Sept 2024, 04:48
              #6

              @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?

              • https://doc.qt.io/qt-6/qtdesigner-customwidgetplugin-example.html

              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 9 Sept 2024, 04:49 last edited by
                #7

                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.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                J 1 Reply Last reply 9 Sept 2024, 20:36
                1
                • Christian EhrlicherC Christian Ehrlicher
                  9 Sept 2024, 04:49

                  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.

                  J Offline
                  J Offline
                  jdent
                  wrote on 9 Sept 2024, 20:36 last edited by
                  #8

                  @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?

                  Christian EhrlicherC 1 Reply Last reply 9 Sept 2024, 20:53
                  0
                  • J jdent
                    9 Sept 2024, 20:36

                    @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?

                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 9 Sept 2024, 20:53 last edited by
                    #9

                    @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.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1

                    1/9

                    8 Sept 2024, 16:22

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved