如何在 pyqt4 的 Qt Designer 中使用提升? [英] How do I use promote to in Qt Designer in pyqt4?

查看:110
本文介绍了如何在 pyqt4 的 Qt Designer 中使用提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计器中,当我右键单击一个小部件,然后单击提升以显示此窗口.请参阅下面的屏幕截图.

In the designer when I right click a widget, and I click promote to I get this window. See the screenshot below.

我从未使用过此功能.基本上,头文件让我感到困惑.它有什么用?这是否意味着我可以在这种情况下创建一个新类,继承 QLineEdit 并向其添加更多方法?提升的类名是什么?

I have never used this feature. Basically, the header file is confusing me. What is it for? Does that mean I can create a new class in this case, inheriting QLineEdit and add more methods to it? What is the promoted class name?

推荐答案

这允许您使用在别处定义的自定义小部件,否则设计师不会知道.

This allows you to use custom widgets defined elsewhere, which designer otherwise wouldn't know about.

例如,如果您定义了一个从 QLabel 派生的小部件 MyLabel,那么您可以在此处定义它,然后只需插入一个 QLabel> 作为您 ui 中的占位符并将其提升到 MyLabel.

For example, if you've defined a widget MyLabel derived from QLabel, then you can define it here and then just insert a QLabel as placeholder in your ui and promote it to MyLabel.

然后 uic 编译器将包含必要的导入/包含,例如,如果您指定 mypackage/mycomponent.h 作为头文件和 MyLabel 作为类名,那么 pyuic 将添加

The uic compiler will then include the necessary imports/includes, for example if you specified mypackage/mycomponent.h as header file and MyLabel as class name, then pyuic will add

from mypackage.mycomponent import MyLabel

(注意.h是如何被忽略的,斜线被pyuic转换为.以保持与python的兼容性)

(note how the .h is ignored, and slashes are converted to . by pyuic to keep compatibility with python)

全局包含被pyuic忽略,它只影响uic(生成#include "mypackage/mycomponent.h"#include for c++)

Global include is ignored by pyuic, it only affects uic (generate #include "mypackage/mycomponent.h" or #include <mypackage/mycomponent.h> for c++)

这篇关于如何在 pyqt4 的 Qt Designer 中使用提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆