简体   繁体   English

如何在 Qt-Designer 中使用自定义小部件

[英]How to use custom widget in Qt-Designer

I want to use a custom widget in the GUI-Designer of Qt-Creator IDE.我想在 Qt-Creator IDE 的 GUI-Designer 中使用自定义小部件。 So i created a class which inherits from Qt's QWidget.所以我创建了一个继承自 Qt 的 QWidget 的类。 It worked to place it on a QMainWindow programaticaly, but have to do my work in the desiger where it does not appear as an option in the kist of components.它可以以编程方式将其放置在 QMainWindow 上,但必须在设计器中完成我的工作,因为它不会在组件列表中显示为选项。

I googled to find a solution for problem an found an manual on, who guesses, the Qt doc page ( https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html and https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html ).我用谷歌搜索找到了问题的解决方案,并在 Qt 文档页面( https://doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.htmlhttps: //doc.qt.io/archives/qt-4.7/designer-creating-custom-widgets.html )。 I tried to follow it but doesn't work.我试图遵循它,但没有奏效。

Does someone know an other way to do this or can give a hint where i can search for problems following this tutorial?有人知道这样做的其他方法,或者可以提示我可以按照本教程搜索问题的位置吗?

Thanks in advance.提前致谢。

Codierknecht编码器

If you are like me, the analog clock example didn't do it for you, in which case I found just one better tutorial.如果您像我一样,模拟时钟示例并不适合您,在这种情况下,我找到了一个更好的教程。 It may be on the kde site but I you dont need kde to do it, it just explains how to make the custom widget a plugin so you can add it into Qt Designer, rather than having to code it in, which is the norm when you just add a widget to your project and customize the class.它可能在 kde 站点上,但我不需要 kde 来执行它,它只是解释了如何将自定义小部件作为插件,以便您可以将其添加到 Qt Designer 中,而不必对其进行编码,这是正常情况下的您只需向您的项目添加一个小部件并自定义该类。 I hope this page helps you like it helped me, get in the right direction of writing a single Qt Designer (or multiple) plugin:我希望这个页面可以帮助你喜欢它对我的帮助,找到编写单个 Qt Designer(或多个)插件的正确方向:

Writing Qt Designer Plugins 编写 Qt 设计器插件

If this link ever becomes dead, just do a search for the link itself, usually that will turn up the original page in someone's cache, as they do in the other examples above (the dead links in the above answers that just take you to main area and not to the pages originally intended).如果此链接失效,只需搜索链接本身,通常会在某人的缓存中打开原始页面,就像他们在上面的其他示例中所做的那样(上述答案中的死链接只会带您进入主页面)区域而不是最初打算的页面)。

There is a different example in the examples section of the Qt documentation that I think is a lot clearer. Qt 文档的示例部分中有一个不同的示例,我认为它更清晰。

Custom Widget Plugin Example 自定义小部件插件示例

It was a little unclear to me when reading the tutorial where the Q_EXPORT_PLUGIN2() macro goes, but having full example code and project alleviates that.在阅读 Q_EXPORT_PLUGIN2() 宏所在的教程时,我有点不清楚,但是拥有完整的示例代码和项目可以缓解这种情况。

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

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