-4

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

Nicholas Johnson
  • 1,012
  • 2
  • 12
  • 35
  • 1
    You definitely need to work on a MCVE example. There is way too much code being posted (and partially, I see a lot of included .pri and .h files that are not posted)....no one will be able to help you on that. – jpo38 Mar 01 '18 at 09:41
  • @jpo38 then help me compile this MCVE example – Nicholas Johnson Mar 02 '18 at 13:46
  • That's your job to provide your post a MCVE. – jpo38 Mar 02 '18 at 13:54
  • 1
    Just take your huge project and remove every useless class code until you get a minimal example reproducing the problem. The more code you remove, the more simple your project will be and then you get a chance for someone to take it and try to fix your issue. – jpo38 Mar 02 '18 at 20:37
  • @jpo38 I have removed much excess code. I think the rest is mandatory. If not let me know. – Nicholas Johnson Mar 04 '18 at 16:58
  • 1
    Apparently, you still don't understand what a MCVE is, please readhttps://stackoverflow.com/help/mcve. I downloaded your content and it still does not compile, included files are missing ("qtmaterialappbar_p.h", "qtmaterialstyle.h", "qtmaterialappbar.pri"...). A good MCVE should be downloadable and should compile....else it does not really help. – jpo38 Mar 04 '18 at 19:22
  • @jpo38 I have minimized the project and it is at the given GitHub link – Nicholas Johnson Mar 05 '18 at 02:39
  • 1
    Download the project from ghitub and try to compile it before supposing it's complete....there are still some files missing (qtmaterialextrafiles.pri, qtmaterialoverlaywidget.h)!!! Is it really hard to try that? – jpo38 Mar 05 '18 at 07:52
  • @jpo38 I will be honest, at first I just thought that someone would have experienced this before, but I definitely could have put much more effort into all of this. I have repaired the files at the GitHub. It should compile successfully now. – Nicholas Johnson Mar 05 '18 at 22:12
  • It now compiles. However, I don't see any custom widget being added to Qt Designer. When you say "I successfully see the list of all my widgets in Qt Designer", how did you make them be available? – jpo38 Mar 06 '18 at 07:08
  • @jpo38 you probably need to build the project using **the same toolchain** used to build Qt Creator. – p-a-o-l-o Mar 06 '18 at 08:58
  • @NicholasJohnson I guess you read this, already: http://doc.qt.io/qtcreator/adding-plugins.html#matching-build-keys – p-a-o-l-o Mar 06 '18 at 09:06
  • @p-a-o-l-o: I'm using one and only one toolchain – jpo38 Mar 06 '18 at 09:26
  • @jpo38 so you have built creator by yourself, right? – p-a-o-l-o Mar 06 '18 at 09:27
  • @p-a-o-l-o: No, just built Nicholas's project, you mean you lneed to recompile QtCreator with this plugin added? Did not tried that. You may give it a chance if you are familiar with that now a MCVE was posted. – jpo38 Mar 06 '18 at 11:41
  • @jpo38 Set the project to release. Then build. Go to the release folder. There should be a *.dll file. Move that to the designer plugins folder. – Nicholas Johnson Mar 06 '18 at 11:58
  • Per http://doc.qt.io/qt-5/qtdesigner-customwidgetplugin-example.html, try setting QT_DEBUG_PLUGINS in your environment and seeing if that gets you helpful diagnostic information. Just glancing at your code, though, are you missing a Q_PLUGIN_METADATA macro in QtMaterialBadgePlugin? – eclarkso Mar 07 '18 at 02:16
  • I confirm the code from github now compiles (just remove the reference to icons.qrc) and makes it possible to see the plugin in Qt Designer and reproduce the bug. – jpo38 Mar 07 '18 at 10:10
  • @eclarkso when I did add that meta data attribute it said a redefinition occurred. – Nicholas Johnson Mar 07 '18 at 14:48
  • @jpo38 i just cannot drag the widget to the scene. – Nicholas Johnson Mar 07 '18 at 14:48
  • @NicholasJohnson Did you try defining QT_DEBUG_PLUGINS? – eclarkso Mar 07 '18 at 15:01

1 Answers1

2

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:

  • the top level's "ui" XML node, but that's apparently optionnal as the plugin works even without that
  • the geometry property (which is used to determine the default size used during drag and drop). That was the root cause of your problem!

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!

jpo38
  • 20,821
  • 10
  • 70
  • 151
  • Thank you very much! I apologize for the failed few entries that I submitted as they were "half-assed" Thank you for taking the time to assist me with this. I have some different errors, nut I'm sure I'll resolve them. – Nicholas Johnson Mar 07 '18 at 20:54