[Interest] How to use QOpenGLWidget from Qt Creator

Nicholas Yue yue.nicholas at gmail.com
Mon May 3 20:21:45 CEST 2021


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 <max-l at 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 at qt-project.org
> > https://lists.qt-project.org/listinfo/interest
> >
> _______________________________________________
> Interest mailing list
> Interest at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210503/6927296e/attachment.html>


More information about the Interest mailing list