Integrating Custom Widgets with Qt Designer



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



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



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



  • 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


  • Moderators

    This post is deleted!


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



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


  • Qt Champions 2016

    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)



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



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



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


  • Moderators

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


  • Qt Champions 2016

    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. :)



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.