14

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
  • possible duplicate of [Promote PyQt Widget](http://stackoverflow.com/questions/4832695/promote-pyqt-widget) – ekhumoro Oct 27 '13 at 19:22

1 Answers1

29

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++)

mata
  • 67,110
  • 10
  • 163
  • 162
  • 23
    **This is inscrutable black magic.** The Qt (Creater|Designer) UX *really* needs to explicitly acknowledge the existence of other languages other than C++. The need to specify a C++ header file, whose filetype `pyuic` and `pysideuic` then silently ignore, is particularly unforgivable. – Cecil Curry Jun 20 '17 at 07:11