Search code examples
qtdesigner

Qt Design Promoted Qpushbutton parameterised constructor


I've been learning about subclassing and widget promotion in Qt Designer and I've promoted some QPushButtons. My promoted class represents the number keys on a calculator, and takes a parameter in the constructor. The parameter given is the number of the button and it is passed in as an int.

Is there a way to tell Qt Designer how to construct each button? The constructor needs the numbers 0-9 passed to it. If I manually modify the generated code it works; however, each time it generates the form, I have to manually edit it.


Solution

  • There is no simple way to achieve this while keeping your argument in the constructor I'm afraid (read this page in the docs to how you might go about it).

    I think your best solution is to keep the constructor mirroring that of QPushButton (i.e. just passing a parent QWidget) and set your custom data by calling a function afterwards.