Incorrect viewport problem..

I am working on a CAD type application,where i am using multiple QOpenglWidgets. I am trying to render a SAMPLE Triangle but the viewport position is incorrect.

//This the resize function-------------------------------------------------

void resizeEvent(QResizeEvent * event) 
    unsigned int width=event->size().width();
    unsigned int height=event->size().height();

    if (height == 0) height = 1;                
   GLfloat aspect = (GLfloat)width / (GLfloat)height;
   glViewport(0, 0, width, height);
   if (width >= height)
     // aspect >= 1, set the height from -1 to 1, with larger width
      gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
      // aspect < 1, set the width to -1 to 1, with larger height
     gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);

// And from PaintEvent i am calling this-------------------

void SAMPLE_OPENGL(float Ty)

  glMatrixMode(GL_MODELVIEW);      // To operate on Model-View matrix
   glLoadIdentity();                // Reset the model-view matrix
    glBegin(GL_LINES); // sample X,Y axis (in immediate mode) (Just to check)
    glColor3f(1,0,0);              //X
      glVertex2f(-1.0f, 0.0f);
      glVertex2f( 3.0f, 0.0f);
    glColor3f(0,1,0);              //Y
      glVertex2f( 0.0f, 1.0f);
      glVertex2f( 0.0f, -1.0f);
   glTranslatef(0, Ty, 0.0f); // Translate left and up
   glBegin(GL_TRIANGLES);          // Each set of 3 vertices form a triangle
      glColor3f(0.0f, 0.0f, 1.0f); // Blue
      glVertex2f(0.2f, 0.2f);
      glColor3f(1.0f, 0.0f, 0.0f); // Red
      glVertex2f(0.8f, 0.2f);
      glColor3f(0.0f, 1.0f, 0.0f); // Green
      glVertex2f(0.5f, 0.6f);

//Note there are multiple QOpenglWidgets
//Here is the screenshot of output

Please be sure to wrap your code in code tags to make it easier to read. You will also need to post what the problem is that you are having, what you have tried and not tried. I suggest your re-read the Forum Posting Guidelines. These will help you get an accurate answer.

Override the resizeGL() and paintGL() methods rather than the generic QWidget methods.

QOpenGLWidget overrides paintEvent() and resizeEvent(), and if you override those in a subclass you need to re-implement the relevant functionality from the QOpenGLWidget methods, and you aren’t doing that.

Yah That worked…i replaced resizeEvent() and paintevent()…with resizeGL() and paintGL() respectively. Thank you so much!!!