I guess since you're loading the UI dynamically, you'll need to either go the "plugin" route or subclass QUiLoader.

https://forum.qt.io/topic/68045/can-t-load-custom-widget-using-quiloader

I'm not sure why you're using dynamic UI loading in the first place, or how you expect any custom objects in such external UI files to be available to the application... or if this is a one-time sort of issue. My point being that you may be better off using plugins to being with, since dynamically loading UI files has very limited functionality.

Cheers,
-Max

(Please reply to list, or directly, not both.)


On 5/3/2021 2:21 PM, Nicholas Yue wrote:
Thanks Max,

  I tried the promotion approach and created the corresponding class (which subclass from QOpenGLWidget) but when I ran the code, I can the following message

```
"QFormBuilder was unable to create a custom widget of the class 'MyOpenGLWidget'; defaulting to base class 'QOpenGLWidget'."
```

The full source is here
https://github.com/nyue/QtQuestions/tree/main/Qt5/opengl/mainwindow


Cheers

On Sun, 2 May 2021 at 23:13, Max Paperno <ma...@wdg.us <mailto:ma...@wdg.us>> wrote:

    Hi Nicholas,

    What you want to do is create your custom QOpenGLWidget first (it could
    be the bare minimum to start with, even just a header file with the
    class declaration).  Then in Qt Creator/Designer you want to "promote"
    the placeholder QOpenGLWidget to your custom version.  If you search on
    "promote widget in Qt Designer" (or similar) you'll find more clues.
    Here's a couple links to get you started.

    
https://stackoverflow.com/questions/8138711/creating-custom-widget-to-be-promoted-in-qt-designer

    https://doc.qt.io/archives/qt-4.8/designer-using-custom-widgets.html
    (see "Promoting Widgets" part).

    Note that most customization to your widget won't actually show up in
    Designer (it will act as a "generic" QOpenGLWidget in Designer). Nor
    would any custom properties you create, etc. For that you'd need closer
    integration by writing a plugin (which you probably don't need to
    do).  See:

    
https://stackoverflow.com/questions/58714879/my-custom-widget-is-not-shown-in-qt-creator-qt-designer-but-it-is-shown-when-i

    https://stackoverflow.com/questions/23275909/adding-widgets-to-qt-designer


    HTH,
    -Max


    On 5/3/2021 1:12 AM, Nicholas Yue wrote:
     > Hi,
     >
     > I used designer to create a QOpenGLWidget on a MainWindow
     >
     > I can retrieve the widget via findChild<QOpenGLWidget*>()
     >
     > My understanding is that to leverage the widget, there are a
    couple of
     > virtual methods that needs to be overridden e.g. paintGL(),
    resizeGL(),
     > initializeGL()
     >
     > However, the widget I retrieve via findChild() will be the base
    class
     > without the overridden methods.
     >
     > I must be missing something here.
     >
     > Where can I read up more on how this can be resolved ?
     >
     > The OpenGL examples I found did not use Qt Creator to create the UI
     >
     > https://doc.qt.io/qt-5/qtopengl-hellogl2-example.html
     >
     > Cheers
     > --
     > Nicholas Yue
     > Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
     > Custom Dev - C++ porting, OSX, Linux, Windows
     > http://au.linkedin.com/in/nicholasyue
     > https://vimeo.com/channels/naiadtools
     >
     > _______________________________________________
     > Interest mailing list
     > Interest@qt-project.org <mailto:Interest@qt-project.org>
     > https://lists.qt-project.org/listinfo/interest
     >
    _______________________________________________
    Interest mailing list
    Interest@qt-project.org <mailto:Interest@qt-project.org>
    https://lists.qt-project.org/listinfo/interest



--
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to