Use the script engine to alter your GUI

  • Hey everyone,

    I was wondering whether it is possible to use the script engine to for example add a new button or some other widget to my main apps' gui?

  • Sure you can. I do it in my application.
    All I do is that I "expose" the QMainWindow and then I can access and modify its sub-objects.

    @ _eng->globalObject().setProperty("Main", _eng->newQObject(mainWindow));@

  • Hey Julien,

    This is not exactly what I had in mind, I don't want to make an objects' public slots available to the engine but ad a new widget that did not even exist in the beginning of the program. Until now the best thing I could find was to create a new custom object that inherits the widget I want and use a function that when called will create the aforementioned (and only that) widget. I was wondering if there are other ways, or if even this is a good idea to begin with. I am doing this as an exercise and to be honest can't think how it can actually be useful, except maybe for the case when a user would be able to create his own gui, or customise an existing one.

  • My point was that once you have access to Main, then you can easily insert your script-created widgets into an existing Toolbar, layout or DockWidget.

  • Indeed, and you are absolutely right in that regard. What is not very clear to me at this point though is how can I create a new widget from inside my script, something that I should have stated more clearly in my question.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.