Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create a OpenGL widget in Qt and Visual Studio?
Forum Updated to NodeBB v4.3 + New Features

How to create a OpenGL widget in Qt and Visual Studio?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 980 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcia3x
    wrote on 8 Jan 2023, 05:34 last edited by
    #1

    I'm trying to create a OpenGL widget using Qt 6.4 and VStudio 2022, i have enable the Qt OpenGL widget under the modules, but i still getting a lot of compile errors:

    LNK2019	unresolved external symbol "__declspec(dllimport) public: __cdecl QOpenGLWidget::QOpenGLWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QOpenGLWidget@@QEAA@PEAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function "public: void __cdecl Ui_MainWindowClass::setupUi(class QMainWindow *)" (?setupUi@Ui_MainWindowClass@@QEAAXPEAVQMainWindow@@@Z)
    

    I'm testing in a 'clean' project containing nothing more than a OpenGlWidget added trough QT Designer.

    The includes i have added:

    #include <QtWidgets>
    #include <QtOpenGL>
    

    My project configuration:

    enter image description here

    I have also tried adding, into Linker -> General -> Additional Library directories:

    D:\Qt\6.4.0\msvc2019_64\lib;
    

    And at Linker -> Input -> Additional Dependencies:

    Qt6OpenGL.lib
    

    But i continue getting the same errors.

    I have installed everything in the Qt Maintenance tool, what i'm missing?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 8 Jan 2023, 12:03 last edited by
      #2

      It's just an unfortunate omission of the plugin. It doesn't list QtOpenGLWidgets in the module list popup.

      Don't add linker stuff manually. In the project settings simply enter the name of the module manually instead of using the popup list i.e. in the "Qt Modules" property replace
      core;gui;widgets;opengl
      with
      core;gui;widgets;opengl;openglwidgets
      for both Release and Debug configs.

      M 1 Reply Last reply 8 Jan 2023, 12:48
      1
      • C Chris Kawa
        8 Jan 2023, 12:03

        It's just an unfortunate omission of the plugin. It doesn't list QtOpenGLWidgets in the module list popup.

        Don't add linker stuff manually. In the project settings simply enter the name of the module manually instead of using the popup list i.e. in the "Qt Modules" property replace
        core;gui;widgets;opengl
        with
        core;gui;widgets;opengl;openglwidgets
        for both Release and Debug configs.

        M Offline
        M Offline
        Marcia3x
        wrote on 8 Jan 2023, 12:48 last edited by
        #3

        @Chris-Kawa thank you! now it is compiled correctly!

        Is OpenGL Widget a good choice of widget to display images in a GUI?

        C 1 Reply Last reply 8 Jan 2023, 13:00
        1
        • M Marcia3x
          8 Jan 2023, 12:48

          @Chris-Kawa thank you! now it is compiled correctly!

          Is OpenGL Widget a good choice of widget to display images in a GUI?

          C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 8 Jan 2023, 13:00 last edited by
          #4

          @Marcia3x said:

          Is OpenGL Widget a good choice of widget to display images in a GUI?

          It's a very broad question. It depends.

          OpenGL is a hardware accelerated low level api. It's very powerful but for simple stuff requires more work - writing shaders, managing transformations and GPU resources etc.

          If all you want to do is display a static image you can just use a QLabel with pixmap set on it. If you need more control over how the image is painted you can subclass a widget and use QPainter to draw the image the way you want. If you need to compose it into a larger scene you can use QGraphicsView with an image element in it etc. If you need more advanced animations or shading OpenGL can be a good way to go.

          M 1 Reply Last reply 8 Jan 2023, 15:48
          0
          • C Chris Kawa
            8 Jan 2023, 13:00

            @Marcia3x said:

            Is OpenGL Widget a good choice of widget to display images in a GUI?

            It's a very broad question. It depends.

            OpenGL is a hardware accelerated low level api. It's very powerful but for simple stuff requires more work - writing shaders, managing transformations and GPU resources etc.

            If all you want to do is display a static image you can just use a QLabel with pixmap set on it. If you need more control over how the image is painted you can subclass a widget and use QPainter to draw the image the way you want. If you need to compose it into a larger scene you can use QGraphicsView with an image element in it etc. If you need more advanced animations or shading OpenGL can be a good way to go.

            M Offline
            M Offline
            Marcia3x
            wrote on 8 Jan 2023, 15:48 last edited by
            #5

            @Chris-Kawa drawing a image in a qlabel, when you resize or animate it, it uses too much cpu.

            I wonder if in a opengl widget what will be used is the gpu?

            1 Reply Last reply
            1
            • C Offline
              C Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on 8 Jan 2023, 16:47 last edited by
              #6

              I wonder if in a opengl widget what will be used is the gpu?

              It depends on what you do with it. If you just upload the image as a texture and display it as a quad then yes, the work is done mostly by the GPU. If you modify the image and need to re-upload it often then both CPU and GPU will be involved.

              Widgets are rendered on the CPU, so the load in case of animation is expected, especially if the image is large or the widget is big. Widgets are not generally suited for animations, rather for static UIs.
              If you're interested in animated UIs you might also want to take a look at QtQuick. It is backed by OpenGL (or Vulkan or Direct3D depending on your platform) but has a easier and higher level declarative syntax.

              1 Reply Last reply
              0

              1/6

              8 Jan 2023, 05:34

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved