Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying QImage on screen
Qt 6.11 is out! See what's new in the release blog

Displaying QImage on screen

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 11.2k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jdarnold
    wrote on last edited by
    #1

    I currently pass the "bits" pointer of a QImage to our video decoder, which renders incoming video frames into this buffer. I have a timer that goes off and, if the frame has been changed, "updates" the widget to blit the bits to the window:

    @void VideoWidget::paintEvent(QPaintEvent *)
    {
    QPainter p(this);

    p.drawImage(imagex,imagey,*videoImage);
    

    }
    @

    This works pretty well, although I wonder if it is the most efficient. But now I want to add scroll bars to the widget so that if it is resized to be smaller than the QImage, it shows scroll bars instead of scaling it to the size of the widget. I'm not having too much luck with creating a scroll area with a label on the widget and using the same algorithm as the above:

    @void VideoWidget::VideoWidget()
    {
    ...
    vpix = QPixmap::fromImage(*videoImage);
    ui->imageLabel->setPixmap(vpix);
    ...
    }

    void VideoWidget::paintEventx(QPaintEvent *)
    {
    if ( !vpix.isNull() )
    {
    QPainter p(this->ui->imageLabel->pixmap());

        p.drawImage(imagex,imagey,*videoImage);
    }
    

    }
    @

    Any other way of doing this?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jdarnold
      wrote on last edited by
      #2

      Well, FWIW, this seems to work, although I'm not sure how efficient it is:

      @void VideoWidget::DoUpdate()
      {
      vpix.convertFromImage(*videoImage);
      ui->imageLabel->setPixmap(vpix);
      repaint();
      }
      @

      I'm not sure why I need to keep calling setPixmap. Why doesn't my update to it just show up when I repaint? If I take out the setPixmap, no updates show on the screen.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Hi jdarnold,

        this->ui->imageLabel->pixmap() returns a const QPixmap*. This means a pointer to a const pixmap. So I think, it's clear why it does not work. Although, the label will not know, that it's contents was changed.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jdarnold
          wrote on last edited by
          #4

          Yes, I realized soon after posting the first one that the code wasn't even compiling :( But, after more tweaking, I ended up with the second bit of code and now I'm wondering why I need to keep calling setPixmap. I've commented out the repaint() call and it still works, so it is the setPixmap that does the heavy lifting. I'm wondering how inefficient it is, as I do this a lot. Intuitively, I would think that just updating the pixmap and, perhaps, doing a repaint, should update the image on the screen, but it does not.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jdarnold
            wrote on last edited by
            #5

            Still wondering if there is a more efficient way of rapidly blitting a QImage to the screen, as this current method seems to be pretty slow.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Look into using OpenGL instead.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jdarnold
                wrote on last edited by
                #7

                You know, that's a great idea. We probably need more efficient graphics than can be provided with the native libraries.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved