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. Can't link QOpenGLWidget into a Form
Forum Updated to NodeBB v4.3 + New Features

Can't link QOpenGLWidget into a Form

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 1.1k Views 2 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.
  • SGaistS SGaist

    In that case, let's take another way. Put a layout in your UI and add your OpenGL widget to it. This will likely be simpler in the short run.

    J Offline
    J Offline
    JesusM
    wrote on last edited by JesusM
    #5

    @SGaist How an I add my OpenGLWIdget to the UI instead of adding an empty one?. I am adding the widgets from here:
    0_1560237605948_Captura.PNG

    It has to be something with the context, I was not using any function related with the context when I hadn't the UI but It seems that now I need to use it and I don't know how.

    jsulmJ 1 Reply Last reply
    0
    • J JesusM

      @SGaist How an I add my OpenGLWIdget to the UI instead of adding an empty one?. I am adding the widgets from here:
      0_1560237605948_Captura.PNG

      It has to be something with the context, I was not using any function related with the context when I hadn't the UI but It seems that now I need to use it and I don't know how.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @JesusM said in Can't link QOpenGLWidget into a Form:

      How an I add my OpenGLWIdget to the UI instead of adding an empty one?

      @SGaist suggested to do it in your code manually (not using Designer).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply
      1
      • jsulmJ jsulm

        @JesusM said in Can't link QOpenGLWidget into a Form:

        How an I add my OpenGLWIdget to the UI instead of adding an empty one?

        @SGaist suggested to do it in your code manually (not using Designer).

        J Offline
        J Offline
        JesusM
        wrote on last edited by
        #7

        @jsulm ok I will try it now.

        1 Reply Last reply
        0
        • SGaistS SGaist

          In that case, let's take another way. Put a layout in your UI and add your OpenGL widget to it. This will likely be simpler in the short run.

          J Offline
          J Offline
          JesusM
          wrote on last edited by
          #8

          @SGaist ok, It works but it creates the widget at the bottom:
          0_1560240438164_Captura.PNG

          and I need to have it on the left side, as I had it before creating it manually:
          0_1560240464315_captura2.PNG
          This is my hierarchy (with the empty QOpenGLWidget):
          0_1560240518121_Captura3.PNG
          I added the widget to the centralWidget which has a grid layout. With the Qt Designer I just needed to drag my widget to the left margin to move it to the left but now I can't do it as I created the widget by code.

          jsulmJ 1 Reply Last reply
          0
          • J JesusM

            @SGaist ok, It works but it creates the widget at the bottom:
            0_1560240438164_Captura.PNG

            and I need to have it on the left side, as I had it before creating it manually:
            0_1560240464315_captura2.PNG
            This is my hierarchy (with the empty QOpenGLWidget):
            0_1560240518121_Captura3.PNG
            I added the widget to the centralWidget which has a grid layout. With the Qt Designer I just needed to drag my widget to the left margin to move it to the left but now I can't do it as I created the widget by code.

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #9

            @JesusM said in Can't link QOpenGLWidget into a Form:

            I added the widget to the centralWidget

            You should add it to the layout at desired position.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply
            0
            • jsulmJ jsulm

              @JesusM said in Can't link QOpenGLWidget into a Form:

              I added the widget to the centralWidget

              You should add it to the layout at desired position.

              J Offline
              J Offline
              JesusM
              wrote on last edited by
              #10

              @jsulm this is the layout where I want to add it. I had the QOpenGLWidget in that layout and it was ok as you can see in the second image.

              jsulmJ 1 Reply Last reply
              0
              • J JesusM

                @jsulm this is the layout where I want to add it. I had the QOpenGLWidget in that layout and it was ok as you can see in the second image.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #11

                @JesusM I'm a bit lost now. You should remove that QOpenGLWidget you added in the Designer and instead add one via code and insert it in same layout.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @JesusM I'm a bit lost now. You should remove that QOpenGLWidget you added in the Designer and instead add one via code and insert it in same layout.

                  J Offline
                  J Offline
                  JesusM
                  wrote on last edited by JesusM
                  #12

                  @jsulm I think I didn't explain myself well, sorry. The hierarchy that I posted is before I added the QOpenGLWidget by code, just to show you where I had it added. When I added it by code I removed that component from the Qt Designer so, now, my hierarchy in the Qt Designer hasn't got that component.

                  I added this code to the constructor of my UI to add the QOpenGLWidget:

                  QSurfaceFormat format;
                      format.setDepthBufferSize(24);
                      format.setStencilBufferSize(8);
                      format.setVersion(4, 1);
                      format.setProfile(QSurfaceFormat::CoreProfile);
                      QSurfaceFormat::setDefaultFormat(format);
                  
                      glwindow *ventana = new glwindow();
                      ventana->setFormat(format);
                      ventana->show();
                      ventana->setMouseTracking(true);
                      ventana->installEventFilter(ventana);
                      std::cout<<"Ventana lanzada"<<std::endl;
                      ui->gridLayout->addWidget(ventana);
                  

                  This code add the QOpenGLWidget but at the bottom of the grid layout.

                  jsulmJ 1 Reply Last reply
                  0
                  • J JesusM

                    @jsulm I think I didn't explain myself well, sorry. The hierarchy that I posted is before I added the QOpenGLWidget by code, just to show you where I had it added. When I added it by code I removed that component from the Qt Designer so, now, my hierarchy in the Qt Designer hasn't got that component.

                    I added this code to the constructor of my UI to add the QOpenGLWidget:

                    QSurfaceFormat format;
                        format.setDepthBufferSize(24);
                        format.setStencilBufferSize(8);
                        format.setVersion(4, 1);
                        format.setProfile(QSurfaceFormat::CoreProfile);
                        QSurfaceFormat::setDefaultFormat(format);
                    
                        glwindow *ventana = new glwindow();
                        ventana->setFormat(format);
                        ventana->show();
                        ventana->setMouseTracking(true);
                        ventana->installEventFilter(ventana);
                        std::cout<<"Ventana lanzada"<<std::endl;
                        ui->gridLayout->addWidget(ventana);
                    

                    This code add the QOpenGLWidget but at the bottom of the grid layout.

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @JesusM said in Can't link QOpenGLWidget into a Form:

                    ui->gridLayout->addWidget(ventana);

                    You don't specify where exactly you want this widget to be in the layout. Take a look at https://doc.qt.io/qt-5/qgridlayout.html#addWidget

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    J 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @JesusM said in Can't link QOpenGLWidget into a Form:

                      ui->gridLayout->addWidget(ventana);

                      You don't specify where exactly you want this widget to be in the layout. Take a look at https://doc.qt.io/qt-5/qgridlayout.html#addWidget

                      J Offline
                      J Offline
                      JesusM
                      wrote on last edited by
                      #14

                      @jsulm all the values I have tried make my program crash. I think I don't understand well how to use the addWidget function.
                      I tried all of this:

                      ui->gridLayout->addWidget(ventana,0,0); // This doesn't crash but the widget is still at the bottom;
                          ui->gridLayout->addWidget(ventana,1,0); //Same here
                      //From here all make my program crash.
                          ui->gridLayout->addWidget(ventana,0,1);
                          ui->gridLayout->addWidget(ventana,1,1);
                          ui->gridLayout->addWidget(ventana,0,0, Qt::AlignLeft);
                          ui->gridLayout->addWidget(ventana,0,1, Qt::AlignLeft);
                          ui->gridLayout->addWidget(ventana,1,0, Qt::AlignLeft);
                          ui->gridLayout->addWidget(ventana,1,1, Qt::AlignLeft);
                      
                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JesusM
                        wrote on last edited by
                        #15

                        I found the solution. I had to set the QSizePolicy of my widget and then place the widget at the top-left side:

                            ventana->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding);
                            ui->gridLayout->addWidget(ventana,0,0);
                        

                        0_1560257501850_Captura.PNG

                        Thanks all for helping :)

                        1 Reply Last reply
                        0

                        • Login

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