therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.48k stars 748 forks source link

Subclassing / Extending QWidget #1085

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi,

I'm trying to subclass/extend a QWidget, actually its a QAbstractButton.

I noticed that the qtdeploy tool is automatically generating constructors as in the following case:

type MyCustomButton struct {
    widgets.QAbstractButton
    val1 int
    val2 int
    _ func() `constructor:"init"`
}

func (w *CustomButton) init() {
    // ...
}

qtdeploy is generating "NewMyCustomButton()"

My question is: Is it possible to add arguments to the constructor, in the above example code I would want to pass val1 and val2 to the constructor.

MarSoft commented 3 years ago

Looks like this is impossible. The constructor being created (NewMyCustomButton) will always accept just one argument - parent of type widgets.QWidget_ITF. And the function you provide as an "initializer" (init) will always be called with no arguments.

MarSoft commented 3 years ago

So I think the only sensible way to achieve anything similar is to set required stuff after creating an instance of your class.