PDA

View Full Version : Add GUI on QGraphicsView problem.



yuan-cheng
25th April 2014, 10:55
Hi everyone

I'm using QGraphicsView drawbackground() to draw my openGL texture


void
Gview::drawBackground(QPainter *painters, const QRectF &rect)
{
if(isFirstImg){
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGB,
1920,
1080,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
m_rgbSrc );


isFirstImg = false;
}else
{
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
1920,
1080,
GL_RGB,
GL_UNSIGNED_BYTE,
m_rgbSrc);
}

glViewport(0,0,(GLint)this->width(), (GLint)this->height());

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
{
glTexCoord2f(0.0f, 1.0f);glVertex2f(-1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f);glVertex2f( 1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f);glVertex2f( 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f);glVertex2f(-1.0f, 1.0f);
}
glEnd();
glDisable(GL_TEXTURE_2D);
glFlush();
isUpdated = false;

}

and I add some GUI in QGraphicsScene in QGraphicsView.


m_scene = new QGraphicsScene();
m_view = new Gview();
m_view->setViewportUpdateMode(
QGraphicsView::BoundingRectViewportUpdate);

m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
m_view->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
m_view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
m_view->setGraphicsScene(m_scene);
m_view->setGeometry(50,50,300,300);
m_view->show();

QDialog *dialog = new QDialog(0);
dialog->setWindowOpacity(0.5);
dialog->setLayout(new QVBoxLayout);
dialog->layout()->addWidget(new QLabel("Hello!"));
dialog->layout()->addWidget(new QPushButton("Ok", 0));
m_scene->addWidget(dialog, dialog->windowFlags());

sometime the texture is fine, sometime it isn't.

the openGL texture usually disappear in my window and remain the QDialog, if I shut the QDialog window when the programe is running, the openGL texture will be appeared.

so what's the problem??



thanks you help.