Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

python - How do I use promote to in Qt Designer in pyqt4?

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

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?

Promote widget

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...