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. Integrating Custom Widgets with Qt Designer
Forum Updated to NodeBB v4.3 + New Features

Integrating Custom Widgets with Qt Designer

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 5.4k Views 2 Watching
  • 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    Hi,
    I'm trying to do the task Integrating Custom Widgets with Qt Designer.
    For that, I made a project named IconEditorPlugin with this .pro file:

    0_1510657964190_Capture.PNG

    When I run the project I get the following errors:

    1- C:\Qt\5.9\mingw53_32\include\QtCore\qglobal.h:733: error: expected ';' at end of input
    #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

    2- C:\Qt\5.9\mingw53_32\include\QtCore\qglobal.h:733: error: static assertion failed: Old plugin system used
    #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

    Apart from these, when I from another project go to the Designer mode and widget box, there is no isonEditor widget there!

    Where have I made mistakes please?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @tomy said in Integrating Custom Widgets with Qt Designer:

      Old plugin system used

      This is one of the cases where the book shows its age. Here you can find an example that shows you the Qt5 way but, in reality, unless you are planning to release the widget to the public, you can just add a normal QWidget into designer, right click it and promote it as it's much quicker and easy

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      tomyT 1 Reply Last reply
      3
      • VRoninV VRonin

        @tomy said in Integrating Custom Widgets with Qt Designer:

        Old plugin system used

        This is one of the cases where the book shows its age. Here you can find an example that shows you the Qt5 way but, in reality, unless you are planning to release the widget to the public, you can just add a normal QWidget into designer, right click it and promote it as it's much quicker and easy

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by tomy
        #3

        @VRonin
        Thanks.

        right click it and promote it as it's much quicker and easy

        Right click on what? The project IconEditorPlugin hasn't a .ui file.

        jsulmJ 1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Say you want to use the IconEditor in your own complex widget. instead of adding the IconEditor directly, you add a genreric Widget in designer, right click on it and promote it to tell designer that, when the program is built, that generic widget should in fact be an IconEditor.

          The obvious difference is that, inside designer, it will still show up as a gray box rather than an actual preview but in most cases it's fine

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          tomyT 1 Reply Last reply
          2
          • tomyT tomy

            @VRonin
            Thanks.

            right click it and promote it as it's much quicker and easy

            Right click on what? The project IconEditorPlugin hasn't a .ui file.

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • VRoninV VRonin

              Say you want to use the IconEditor in your own complex widget. instead of adding the IconEditor directly, you add a genreric Widget in designer, right click on it and promote it to tell designer that, when the program is built, that generic widget should in fact be an IconEditor.

              The obvious difference is that, inside designer, it will still show up as a gray box rather than an actual preview but in most cases it's fine

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #6

              @VRonin
              Does it mean that we can use a pushButton as an iconEditor that way!?
              I would like if we want to use a custom widget, say, that iconEditor, we could have it like any other widget in the widget box and would drag and drop and use it.

              VRoninV 1 Reply Last reply
              0
              • tomyT tomy

                @VRonin
                Does it mean that we can use a pushButton as an iconEditor that way!?
                I would like if we want to use a custom widget, say, that iconEditor, we could have it like any other widget in the widget box and would drag and drop and use it.

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @tomy said in Integrating Custom Widgets with Qt Designer:

                I would like if we want to use a custom widget, say, that iconEditor, we could have it like any other widget in the widget box and would drag and drop and use it.

                That's what the first link is for: http://doc.qt.io/qt-5/designer-creating-custom-widgets.html

                While it looks cool, in my experience, most of the time you won't bother using it in production code and just go for the promote solution as it's quicker. I would go as far as to suggest you just skip to the next part of the book as Qt Designer plugins are huge niche.

                Does it mean that we can use a pushButton as an iconEditor that way!?

                Not really, the iconEditor would need to be a subclass of QPushButton for that to work. since all widgets are subclasses of QWidget, you can always use that safely

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                4
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #8

                  Also as a note to Designer plugin.
                  Since you are using mingw compiler, a full blown plugin for Designer will not just work.

                  The reason for that is a Designer plugin is a DLL and for Creator to load it, it must be made
                  with SAME version of compiler as Creator was.

                  On windows, it means you must be using visual studio compiler and not mingw.

                  This not a restriction from Qt. its how DLLS works and goes for all frameworks.
                  The only cure is to compile a new Creator with mingw OR use visual studio compiler.

                  The promotion feature offer a easier way to use a custom widget in an UI file and
                  is far less work.
                  You can drag it back to the widget list to have as the other widgets. ( after you promote it)
                  Its under "Scratch pad" label. (in bottom)

                  1 Reply Last reply
                  4
                  • tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by
                    #9

                    thank you all very much for your info.
                    I think those approaches (promotion or plugin) are not used often. But I will keep this guidance in mind for farther use.

                    VRoninV 1 Reply Last reply
                    0
                    • tomyT tomy

                      thank you all very much for your info.
                      I think those approaches (promotion or plugin) are not used often. But I will keep this guidance in mind for farther use.

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by VRonin
                      #10

                      @tomy said in Integrating Custom Widgets with Qt Designer:

                      I think those approaches (promotion or plugin) are not used often

                      Promotion is used. A lot. You basically can only avoid it if you don't use ui files and build everything in code

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      tomyT 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        @tomy said in Integrating Custom Widgets with Qt Designer:

                        I think those approaches (promotion or plugin) are not used often

                        Promotion is used. A lot. You basically can only avoid it if you don't use ui files and build everything in code

                        tomyT Offline
                        tomyT Offline
                        tomy
                        wrote on last edited by tomy
                        #11

                        @VRonin
                        So we could conclude that if we write Qt programs by hand code we won't be able to use the promotion approach, and we will be led to the plugin approach. This approach too is not very handy because the issues it has as mrjj spotted them. Right?

                        jsulmJ VRoninV 2 Replies Last reply
                        0
                        • tomyT tomy

                          @VRonin
                          So we could conclude that if we write Qt programs by hand code we won't be able to use the promotion approach, and we will be led to the plugin approach. This approach too is not very handy because the issues it has as mrjj spotted them. Right?

                          jsulmJ Online
                          jsulmJ Online
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by jsulm
                          #12

                          @tomy No!
                          If you do not use Designer (if you write UI code by hand) you do not need promotion AND plug-in approach!
                          Both are needed only when using Designer.

                          1 Reply Last reply
                          1
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by mrjj
                            #13

                            Hi
                            Just to be clear
                            Promotion is a feature to allow a custom widget to be used in Designer with UI files.

                            It is basically a Replace at Runtime feature allowing you to design UI files with your customs widgets
                            without having to make them full blown Designer plugins. ( which is far more work )
                            Using promotion , you can draw the GUI using Designer and it will use your custom widget when run.

                            I use promotion all the time. Its one of my favorite features allowing me both to use custom widgets AND
                            use Designer for drawing the GUI.
                            If you use Designer, its a feature you will want to use. :)

                            tomyT 1 Reply Last reply
                            3
                            • tomyT tomy

                              @VRonin
                              So we could conclude that if we write Qt programs by hand code we won't be able to use the promotion approach, and we will be led to the plugin approach. This approach too is not very handy because the issues it has as mrjj spotted them. Right?

                              VRoninV Offline
                              VRoninV Offline
                              VRonin
                              wrote on last edited by
                              #14

                              @tomy said in Integrating Custom Widgets with Qt Designer:

                              Right?

                              No. I never use Qt Designer to build my ui but just do everything by hand, for example:

                              QWidget mainWid;
                              auto mainLay = new QVBoxLayout(&mainWid);
                              mainLay->addWidget(new QLabel("Test Label",&mainWid));
                              mainLay->addWidget(new QPushButton("Useless Button",&mainWid));
                              mainWid.show();
                              

                              If, instead, you use Qt Designer, promotion will be almost impossible to avoid.

                              Designer plugins are only really relevant if you are developing widgets for other programmers to use and you want nice integration with Qt Designer, for example: http://www.devmachines.com/qtitandatagrid-overview.html

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              1 Reply Last reply
                              4
                              • mrjjM mrjj

                                Hi
                                Just to be clear
                                Promotion is a feature to allow a custom widget to be used in Designer with UI files.

                                It is basically a Replace at Runtime feature allowing you to design UI files with your customs widgets
                                without having to make them full blown Designer plugins. ( which is far more work )
                                Using promotion , you can draw the GUI using Designer and it will use your custom widget when run.

                                I use promotion all the time. Its one of my favorite features allowing me both to use custom widgets AND
                                use Designer for drawing the GUI.
                                If you use Designer, its a feature you will want to use. :)

                                tomyT Offline
                                tomyT Offline
                                tomy
                                wrote on last edited by
                                #15

                                @mrjj
                                Hi,
                                Thanks for your clarification. I'm still on the side of using Qt by everything in code no Designer. It may or may not change in the future. :)

                                @VRonin
                                Thanks.

                                1 Reply Last reply
                                0

                                • Login

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