如何在 Qt-Designer 中使用自定义小部件
我想在 Qt-Creator IDE 的 GUI-Designer 中使用自定义小部件。 所以我创建了一个继承自Qt的QWidget的类。它有效地放置了 它以编程方式在 QMainWindow 上,但必须在设计器中完成我的工作 它不会作为组件中的一个选项出现。
我在谷歌上搜索问题的解决方案,找到了一本手册,谁猜猜, Qt 文档页面 ( https://doc.qt. io/archives/qt-4.7/designer-creating-custom-widgets.html 和 https://doc.qt.io/archives /qt-4.7/designer-creating-custom-widgets.html)。 我尝试遵循它,但没有成功。
有人知道其他方法可以做到这一点,或者可以提示我可以在哪里搜索 对于遵循本教程的问题?
提前致谢。
科迪克内希特
I want to use a custom widget in the GUI-Designer of Qt-Creator IDE.
So i created a class which inherits from Qt's 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.
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).
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Qt 文档的示例部分中有一个不同的示例,我认为它更清晰。
自定义小部件插件示例
在阅读教程时,我有点不清楚 Q_EXPORT_PLUGIN2() 宏的去向,但是拥有完整的示例代码和项目可以缓解这种情况。
There is a different example in the examples section of the Qt documentation that I think is a lot clearer.
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.
如果您像我一样,模拟时钟示例不适合您,在这种情况下,我找到了一个更好的教程。它可能在 kde 网站上,但我不需要 kde 来做到这一点,它只是解释了如何使自定义小部件成为插件,以便您可以将其添加到 Qt Designer 中,而不是必须对其进行编码,这是正常情况下您只需将一个小部件添加到您的项目并自定义该类即可。我希望这个页面可以帮助您,就像它帮助我一样,找到编写单个 Qt Designer(或多个)插件的正确方向:
编写 Qt Designer 插件
如果此链接失效,通常只需搜索链接本身这将在某人的缓存中显示原始页面,就像他们在上面的其他示例中所做的那样(上面答案中的死链接只会带您到主要区域,而不是最初想要的页面)。
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. I hope this page helps you like it helped me, get in the right direction of writing a single Qt Designer (or multiple) plugin:
Writing Qt Designer Plugins
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).