简体   繁体   English

Qt Widget Plugin 在设计器中没有输出

[英]Qt Widget Plugin No Output in Designer

I have a group of custom widgets that I am implementing into Qt Designer.我在 Qt Designer 中实现了一组自定义小部件。 I have successfully built the plugin and have been getting both the .lib and the .dll files outputted.我已经成功构建了插件,并且输出了.lib.dll文件。 I successfully see the list of all my widgets in Qt Designer.我成功地在 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.编辑:我被告知要为我的项目创建一个 MCVE,以使其易于编译和调试。 So I have.所以我有。 https://github.com/NickJohn547745/MaterialWidget-MCVE https://github.com/NickJohn547745/MaterialWidget-MCVE

Never worked with Qt Designer plugins before, but this looked interesting.以前从未使用过 Qt Designer 插件,但这看起来很有趣。

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).由于我不熟悉 Qt Designer 插件,因此我将Qt 示例用于 Designer 插件并使其在我的计算机上运行(很容易做到,只需编译,将生成的 .so 复制到 QtDesigner 插件的文件夹中)。

Then, I took your example from github, compiled it and checked that drag and drop does not work as you reported.然后,我从 github 中获取了您的示例,对其进行了编译并检查了拖放操作是否如您所报告的那样不起作用。

Then, I replaced your QtMaterialBadgePlugin by a renamed copy of Qt's AnalogClockPlugin and your QtMaterialBadge by a renamed copy of Qt's AnalogClock .然后,我换成你QtMaterialBadgePlugin通过Qt的的重命名副本AnalogClockPlugin和你QtMaterialBadge通过Qt的的重命名副本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.然后我用你原来的QtMaterialBadge类替换了“Qt 的AnalogClock重命名副本”,新的惊喜......在 Qt 设计器中拖放仍然有效。 Conclusion: there is definitely something wrong with your QtMaterialBadgePlugin !结论:你的QtMaterialBadgePlugin肯定有问题!

So I checked the differences between your QtMaterialBadgePlugin class and Qt's AnalogClockPlugin class.所以我检查了你的QtMaterialBadgePlugin类和 Qt 的AnalogClockPlugin类之间的差异。 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.现在您的插件可以从 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顶级的“ui”XML节点,但这显然是可选的,因为即使没有那个插件也能工作
  • 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.现在,您将看到拖放仅显示一个灰色方形区域(而 Qt 示例显示了模拟时钟的预览),您可能更喜欢在此处预览您的小部件,我会让您解决这个问题. 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!考虑到您的问题我想我的回答已经足够了“但是,当我将一个小部件拖到场景中时,什么都没有。场景上什么都没有,光标中什么也没有,什么也没有”:现在你得到了一些东西!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM