c++qtqt-designerqtplugin

Qt Widget Plugin No Output in Designer


I have a group of custom widgets that I am implementing into Qt Designer. I have successfully built the plugin and have been getting both the .lib and the .dll files outputted. I successfully see the list of all my widgets in Qt Designer. However, when I go to drag a widget into the scene, nothing. Nothing on the scene, nothing in the cursor, just nothing at all. I will provide the relevant code of one my widgets and their corresponding plugin. Any help/comment on the matter is greatly appreciated.

EDIT: I have been told to create a MCVE of my project in order to keep it easy to compile and debug. So I have. https://github.com/NickJohn547745/MaterialWidget-MCVE


Solution

  • Never worked with Qt Designer plugins before, but this looked interesting.

    Here is what I did to end up fixing your problem. I'm just detailing the method here so that you can understand it and possibly apply it yourself later (the method could apply to other kind of problems you could meet).

    As I'm not familiar with Qt Designer plugins, I took Qt example for Designer plugins and made it work on my computer (very easy to do, just compiled, copied the generated .so to QtDesigner plugin's folder).

    Then, I took your example from github, compiled it and checked that drag and drop does not work as you reported.

    Then, I replaced your QtMaterialBadgePlugin by a renamed copy of Qt's AnalogClockPlugin and your QtMaterialBadge by a renamed copy of Qt's AnalogClock. Then I compiled the plugin, and , surprise....I could drag and drop the plugin item, it worked! So there was definitely something wrong with your code.

    Then I replaced back the "renamed copy of Qt's AnalogClock" with your original QtMaterialBadge class and, new surprise...drag and drop still worked in Qt Designer. Conclusion: there is definitely something wrong with your QtMaterialBadgePlugin!

    So I checked the differences between your QtMaterialBadgePlugin class and Qt's AnalogClockPlugin class. That was simple as there's only few lines of code...

    Just replace:

    QString QtMaterialBadgePlugin::domXml() const
    {
        return QLatin1String("<widget class=\"QtMaterialBadge\" name=\"qtMaterialBadge\">\n<widget>\n");
    }
    

    by:

    QString QtMaterialBadgePlugin::domXml() const
    {
        return "<ui language=\"c++\">\n"
                   " <widget class=\"QtMaterialBadge\" name=\"qtMaterialBadge\">\n"
                   "  <property name=\"geometry\">\n"
                   "   <rect>\n"
                   "    <x>0</x>\n"
                   "    <y>0</y>\n"
                   "    <width>100</width>\n"
                   "    <height>100</height>\n"
                   "   </rect>\n"
                   "  </property>\n"
                   " </widget>\n"
                   "</ui>\n";
    }
    

    And now your plugin will be draggable and droppable from Qt Designer. Note that you forgot:

    Now, you'll see drag and drop only shows a gray square area (while Qt example shows a preview of the AnalogClock), you'll probably prefer to have a preview of your widget here, and I'll let you work this out. I suppose my answer is enough considering your question "However, when I go to drag a widget into the scene, nothing. Nothing on the scene, nothing in the cursor, just nothing at all": Now you get something!