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. QWidget with QopenGLwidget
Forum Updated to NodeBB v4.3 + New Features

QWidget with QopenGLwidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 3 Posters 2.6k 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

    Can you show how you are doing that ?

    H Offline
    H Offline
    hjohn
    wrote on last edited by
    #5

    @SGaist

    Not completed yet,

    #include "openglclass.h"
    
    
    openGlClass::openGlClass(QWidget *parent):QOpenGLWidget(parent)
    {
        count=0;
        W= new QWidget(this);
        W->setStyleSheet("background-color : rgb(0,170,127);");
    
       W->setFixedSize(50,40);
    
       QPoint pl= W->geometry().bottomLeft();
       QPoint pr= W->geometry().bottomRight();
        qDebug()<<"point : "<<pr << pl;
        W->show();
    }
    
    void openGlClass::initializeGL()
    {
     qDebug()<<"Initialize"<<count   ;
     //initializeOpenGLFunctions();
    
     glClearColor(0.7,0.7,0.7,1);
     glEnable(GL_LIGHTING);
    }
    void openGlClass::paintGL()
    {
        qDebug()<<"paint"<<count;
        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_LINES);
             glColor3f(1,0,0);
          glVertex2f(0.1f, 0.7f);
          glVertex2f(-0.9f, 0.1f);
         glEnd();
    
    }
    
    void openGlClass::resizeGL(int w, int h)
    {
        qDebug()<<"Resize"<<count;
    
    }
    
    void openGlClass::mousePressEvent(QMouseEvent *event)
    {
    
    }
    
    
    
    
    

    O/p:
    0_1532409871207_Untitled.png

    The Green Box is simple widget and line I have Render in OpenGl,not i want to Bind both so that when i Drag that box the line Should also adjust with that.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @hjohn said in QWidget with QopenGLwidget:

      QPoint pl= W->geometry().bottomLeft();
      QPoint pr= W->geometry().bottomRight();

      These should be class variables. ( live in .h)
      and u do
      pl= W->geometry().bottomLeft();
      pr= W->geometry().bottomRight();
      and also updates them when you move the widget
      and then use them in the
      void openGlClass::paintGL()
      for the line drawings.

      H 1 Reply Last reply
      2
      • mrjjM mrjj

        @hjohn said in QWidget with QopenGLwidget:

        QPoint pl= W->geometry().bottomLeft();
        QPoint pr= W->geometry().bottomRight();

        These should be class variables. ( live in .h)
        and u do
        pl= W->geometry().bottomLeft();
        pr= W->geometry().bottomRight();
        and also updates them when you move the widget
        and then use them in the
        void openGlClass::paintGL()
        for the line drawings.

        H Offline
        H Offline
        hjohn
        wrote on last edited by hjohn
        #7

        @mrjj But Problem is that, Qwidget coordinate system and openGL coordinate system are different.
        In Qwidget,the Origin(0,0) is on top left corner whereas In QOpenglwidget origin(0,0) is centered.
        So,when in Widget if we set Geometry as a

        W->setGeometry(0,0,50,40);
        

        and in line

          glBegin(GL_LINE);
                  glVertex2f(0.0f, 0.0f);
                  glVertex2f(0.5f, 0.5f);
                  glEnd();
        

        Both are rendered in Diffetnt place.
        the Geometry position of widget is set based on Qpoint.
        In openGl is based on Veretex. I have manually scale the values.But how to set it dynamically.Any idea?

        mrjjM 1 Reply Last reply
        0
        • H hjohn

          @mrjj But Problem is that, Qwidget coordinate system and openGL coordinate system are different.
          In Qwidget,the Origin(0,0) is on top left corner whereas In QOpenglwidget origin(0,0) is centered.
          So,when in Widget if we set Geometry as a

          W->setGeometry(0,0,50,40);
          

          and in line

            glBegin(GL_LINE);
                    glVertex2f(0.0f, 0.0f);
                    glVertex2f(0.5f, 0.5f);
                    glEnd();
          

          Both are rendered in Diffetnt place.
          the Geometry position of widget is set based on Qpoint.
          In openGl is based on Veretex. I have manually scale the values.But how to set it dynamically.Any idea?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @hjohn

          yep they live in completely different world.

          You have to make a function that maps between Widget x,y to openGl
          or find a better way to archive what u want.

          Normally one would paint the widget to a texture and show on a plane
          inside the openGl or similar ways. I also think u can paint with QPainter.

          Do you really need the lines to be opengl?

          H 1 Reply Last reply
          0
          • mrjjM mrjj

            @hjohn

            yep they live in completely different world.

            You have to make a function that maps between Widget x,y to openGl
            or find a better way to archive what u want.

            Normally one would paint the widget to a texture and show on a plane
            inside the openGl or similar ways. I also think u can paint with QPainter.

            Do you really need the lines to be opengl?

            H Offline
            H Offline
            hjohn
            wrote on last edited by hjohn
            #9

            @mrjj said in QWidget with QopenGLwidget:

            Normally one would paint the widget to a texture and show on a plane

            If I paint Widget then there is no chance to add something or modify the values display on widget,and I want some data to be displayed on that widget.
            Yes,I need that Line to be OpenGl

            @mrjj said in QWidget with QopenGLwidget:

            You have to make a function that maps between Widget x,y to openGl

            Do You have any Idea,the way to map coordinates.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hjohn
              wrote on last edited by
              #10

              How Can I find coordinates of openGLwidget when mouse press.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #11

                Hi
                Sorry. i have no good idea how to convert in any easy way.

                By mouse Coordinates you mean in Widgets coordinates or as
                actual openGl coordinates?

                H 1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  Sorry. i have no good idea how to convert in any easy way.

                  By mouse Coordinates you mean in Widgets coordinates or as
                  actual openGl coordinates?

                  H Offline
                  H Offline
                  hjohn
                  wrote on last edited by hjohn
                  #12

                  @mrjj said in QWidget with QopenGLwidget:

                  By mouse Coordinates you mean in Widgets coordinates or as
                  actual openGl coordinates?

                  Actual OpenGl coordinates.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @hjohn
                    I do not think openGLwidget directly offer that.
                    I tried to google for it but just too much deprecated fixed pipeline
                    openGl so im not sure how you would do it.

                    This would be very easy to do with QPainter but i guess you want
                    openGl for a reason ?

                    H 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @hjohn
                      I do not think openGLwidget directly offer that.
                      I tried to google for it but just too much deprecated fixed pipeline
                      openGl so im not sure how you would do it.

                      This would be very easy to do with QPainter but i guess you want
                      openGl for a reason ?

                      H Offline
                      H Offline
                      hjohn
                      wrote on last edited by
                      #14

                      @mrjj yeah..
                      No worry.. If I come up with any solution,I will mention here. Thanks for guiding me..

                      1 Reply Last reply
                      1

                      • Login

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