J
J
Julia2017-03-22 15:28:37
Qt
Julia, 2017-03-22 15:28:37

How to repaint QtOpenGlWidget?

Good afternoon. I have a QApplication which consists of 4 tab widgets.
Each tab has a QOpenGlWidget that share with each other context
Unfortunately after I switch tabs Event::Show doesn't work. After mouse click -- then QOpenGLWidget will be redrawn How can I change this?

m_glXRayWidget = new QOpenGLWidget(this);

  if (data->pShareGLContext == NULL)
    data->pShareGLContext = m_glXRayWidget->context();
  else
    m_glXRayWidget->context()->setShareContext(data->pShareGLContext);

bool XrayLoad::event(QEvent* e)
{
  QWidget::event(e);
  if (e->type() == QEvent::Show )
  {
    if (firstTime){
      firstTime = false;
      workerThread = new PatLoadThread(data);
      connect(workerThread, SIGNAL(process()), this, SLOT(progressChanged()));
      connect(workerThread, SIGNAL(finished()), this, SLOT(progressFinished()));
      workerThread->start();
    }
    else{
      update();
    }
  }
  return true;
}

void XrayLoad::paintEvent(QPaintEvent * event)
{
  m_glXRayWidget->makeCurrent();
  glClear(GL_COLOR_BUFFER_BIT);
  if (data->arrayXRay.size() != 0)
  { 
    if (data->arrayXRay[currentXray]->getVisible())
    { 
      int maxDimSize = std::max(m_glXRayWidget->size().width(), m_glXRayWidget->size().height());
      data->arrayXRay[currentXray]->initGL(m_glXRayWidget->size().width(), m_glXRayWidget->size().height());
      data->arrayXRay[currentXray]->GL_RenderXRay(maxDimSize, maxDimSize);
      data->arrayXRay[currentXray]->GL_ApplyCameraCalibration(data->arrayXRay[currentXray]->getZoom(), data->arrayXRay[currentXray]->getPosX(), data->arrayXRay[currentXray]->getPosY(), maxDimSize, maxDimSize, data->arrayXRay[currentXray]->getRotation(), data->arrayXRay[currentXray]->getIsFlipped(), true);  
    }
  }
  // now update openGL window
//	m_glXRayWidget->swapBuffers();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question