Important: Please read the Qt Code of Conduct -

Promoting a widget in Qt Designer

  • I want to promote QWidget to custom widget derived from it. The problem is that the widget expects more arguments to be passed to the constructor and in the generated ui_ file only the parent is passed:

    //constructor is:  QmaxRollup (int category=ROLLUP_CAT_STANDARD, QWidget *parent=nullptr)
    widget_1 = new MaxSDK::QmaxRollup(Form);

    error C2664: 'MaxSDK::QmaxRollup::QmaxRollup(const MaxSDK::QmaxRollup &)': cannot convert argument 1 from 'QWidget *' to 'int'

    The documentation says:
    [...] It exposes properties such as title and category, so they can be easily set in code or in the Qt Designer.

    I already set dynamic properties to the widget in my form, but it doesn't change anything.
    Header file is available here.

  • Lifetime Qt Champion


    What you can do is initialise category directly in the constructor with the ROLLUP_CAT_STANDARD value and add a setter to your class to modify that property.

    You can then do that in your code somewhere more suitable.

  • Hello,

    Thanks for answer

    The class is implemented in static library so I don't think I can cleanly change the source code. I'm just wondering if I can initialize it directly in form to keep things consistent.
    If not, I can always add the widget to the UI after the form is created.

  • Lifetime Qt Champion

    Whether it's a dynamic or static library doesn't really matter. If you have control on it, you can modify the widget and rebuild the library.

Log in to reply