Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realtime pixel drawing in Qt

Tags:

c++

qt

My app display a long scientific vertically-scrollable picture (1024 x 99999999... px) as a sequence of QPixmap 1024x128 blocks. This allows me to scroll a picture with minimal CPU-cost by picking needed blocks from a table: block_id = y_coord/128. Also, QPixmap is preferred "pixel container" for fast screen output.

But now I have a stream of new data coming to the application and need the new data to be added and displayed at the bottom of the long picture. Minimal portion: 1024x1 (a line). Also, I would like to display each new line as soon as possible (close to real-time). Each new portion of 128 lines will be "packed" to QPixmap, but until I received enough data I cannot build a whole block.

What approach should I consider for displaying the new data?

This video gives an idea of "adding new lines of data", except in my case the flow goes up: http://www.youtube.com/watch?v=Dy3zyQNK7jM

like image 766
pavelkolodin Avatar asked Oct 01 '22 17:10

pavelkolodin


2 Answers

You can simply, directly, modify the bottom row of QPixmaps and update() the window (if the bottom row is in range).

You might find using a QImage is more efficient for half-baked rows, depending on how quickly you update/repaint.

like image 94
spraff Avatar answered Oct 13 '22 12:10

spraff


On contemporary Qt, when using the raster backend, QPixmap offers no benefits compared to QImage. Everything is rendered to a big QImage backing buffer that then gets blitted to the screen. So just use QImage.

You can have a QImage that is 128 pixels high, but you only draw the part of it that was already filled with data. The part without data is either not drawn, or hangs below the visible area of the window, and is thus effectively invisible.

like image 26
Kuba hasn't forgotten Monica Avatar answered Oct 13 '22 10:10

Kuba hasn't forgotten Monica