title: QOpenGLWidget and QPainter ,Can’t render 2D and 3D at the same time
body: <p>My Qt version is 5.4.And I test the new class <code>QOpenGWidget</code>,I do as Qt Assistant：put opengl code in QPainter::beginNativePainting ();/QPainter::endNativePainting (); ,but the 2D doesn't show. I don't know what's wrong with my code.This is my code:</p>
  
  <p>.h</p>
  
  <pre><code>class Render : public QOpenGLWidget
  {
  public:
      Render();
      ~Render();
  protected:
      void initializeGL();
      void paintGL();
      void resizeGL(int  w ,int h);
      QOpenGLFunctions_3_3_Core * f;
      QOpenGLBuffer * triangle;
      QOpenGLVertexArrayObject * vao;
      QOpenGLShaderProgram * program;
      QMatrix4x4 mv,p;
      QTimer * time;
      float rota;
      QPainter * painter;
      bool needInit;
      //void paintEvent(QPaintEvent *e);
  
  };
  </code></pre>
  
  <hr>
  
  <p>.cpp</p>
  
  <pre><code>#include "render.h"
  GLfloat tri[] =
  {
      0.0f,1.0f,-1.0f,1.0f,
      1.0f,1.0f,-1.0f,1.0f,
      1.0f,0.0f,-1.0f,1.0f,
  
  };
  Render::Render()
  {
      QSurfaceFormat format;
      format.setDepthBufferSize(24);
      format.setStencilBufferSize(8);
      // format.setVersion(3,3);
      //format.setProfile(QSurfaceFormat::CoreProfile);
  
      setFormat( format);
      rota = 1.5;
      needInit = true;
      //setAutoFillBackground(false);
      time =  new QTimer;
      connect(time,SIGNAL(timeout()),this,SLOT(update()));
      time-&gt;start(50);
  }
  
  Render::~Render()
  {
  
  }
  void Render::initializeGL()
  {
      f = QOpenGLContext::currentContext()-&gt;versionFunctions&lt;QOpenGLFunctions_3_3_Core&gt;();
      f-&gt;initializeOpenGLFunctions();
  
      //f = context()-&gt;functions();
  
  }
  void Render::resizeGL(int w ,int h)
  {
  
      p.setToIdentity();
      p.perspective(35.0f,float(w)/float(h),1.0f,30.0f);
  
  }
  
  void Render::paintGL()
  {
      QPainter pntr(this);
      // painter-&gt;setViewport(50,50,100,100);
      pntr.beginNativePainting();
      QOpenGLShaderProgram  programs ;
      programs.addShaderFromSourceCode(QOpenGLShader::Vertex,
                                       "#version 330 core \n\
                                      layout(location = 0) in vec4 vertex;\
             uniform mat4 mvp;\
     void main() \
     {\
         gl_Position = mvp * vertex;\
     }");
  
      programs.addShaderFromSourceCode(QOpenGLShader::Fragment,
                                       "#version 330 core \n\
                                      out vec4 fragColor;\
             void main() \
     { \
         fragColor = vec4(0.0f,1.0f,0.0f,1.0f);\
     }");
      programs.link();
  
      QOpenGLVertexArrayObject vaos;
      vaos.create();
      f-&gt;glBindVertexArray(vaos.objectId());
      QOpenGLBuffer triangles(QOpenGLBuffer::VertexBuffer);
      triangles.create();
      f-&gt;glBindBuffer(GL_ARRAY_BUFFER,triangles.bufferId());
      triangles.setUsagePattern(QOpenGLBuffer::DynamicDraw);
      triangles.allocate(tri,sizeof(tri));
      programs.enableAttributeArray(0);
      programs.setAttributeBuffer(0,GL_FLOAT,0,4,0);
  
      f-&gt;glEnable(GL_DEPTH_TEST);
  
      needInit = false;
  
      // this-&gt;makeCurrent();
      f-&gt;glViewport(0,0,width(),height());
      f-&gt;glClearColor(1.0f,0.5f,0.5f,1.0f);
      f-&gt;glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
  
      programs.bind();
      mv.setToIdentity();
  
      mv.lookAt(QVector3D(0.0f,0.0f,5.0f),QVector3D(0.0f,0.0f,0.0f),QVector3D(0.0f,1.0f,0.0f));
      mv.rotate(0.5+rota,0,1,0);
      programs.setUniformValue("mvp",p*mv);
      f-&gt;glBindVertexArray(vaos.objectId());
      f-&gt;glDrawArrays(GL_TRIANGLES,0,3);
      rota=rota+1.5;
  
      pntr.endNativePainting();
  
      pntr.drawText(50,100,"Look This!");
  
  }
  </code></pre>