Why display an image on QLabel is faster than displaying the same image on a QGLWidget?
-
I'm writing a code to compare the speed of display the same image on QLabel and on a QGLWidget (one entire black QImage 1000x1000 pixels), but unlike that i expect, display that image on QLabel is faster than display on a QGLWidget. Why? When i use a QGLWidget it's not hardware accelerated? I'm doing something wrong? The time to display the image on QLabel is around 20ms, and on QGLWidget is around 65ms.
My QGLWidget code:
@
void GLWidget::initializeGL()
{
}void GLWidget::resizeGL(int width, int height)
{
}void GLWidget::paintGL()
{
QTime t;
t.start();
QPainter painter(this);
painter.drawImage(this->rect(), img);
qDebug() << "GL" << t.elapsed();
}
@My QLabel code:
@
void MainWindow::display()
{
QTime t;
t.start();
QPixmap pixmap = QPixmap::fromImage(img);
ui->label->setPixmap(pixmap);
qDebug() << "Label" << t.elapsed();
}
@ -
The way your code works the image must likely be transferred to graphics memory of your graphics adapter for every drawing operation, which isn't very efficient. You might want to try QGLWidget::bindTexture and QGLWidget::drawTexture instead. Use bindTexture to prepare the image as texture in graphics memory and drawTexture each time you want to draw your image.