Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Why display an image on QLabel is faster than displaying the same image on a QGLWidget?

    General and Desktop
    2
    2
    2621
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      antonyprojr last edited by

      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();
      }
      @

      1 Reply Last reply Reply Quote 0
      • A
        akonradwesolutions last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post