Qt: an alternative to BitBlt in Qt5 Windows

I am currently porting an open source solution (ATM Albatross solution http://www.albatross.aero/ ) from Qt3 to Qt5. Albatross is an air traffic observer that requires very good results. There are various problems that I managed to manage, but not part of the display.

The display architecture is based on the bitblt command, which first copies one pixmap to another and finally copies pixmap to the screen.

Here is the Qt3 mapping code (working and executive) :

 void CAsdView::paintEvent ( QPaintEvent * Event) { QRect rcBounds=Event->rect(); QPainter tmp; for (int lay=0;lay<(int)m_RectTable.size();lay++) //For each drawing layer (there are 3) { if (!m_RectTable[lay].isEmpty()) { if (lay!=0) bitBlt(m_BitmapTable[lay],m_RectTable[lay].left(),m_RectTable[lay].top(),m_BitmapTable[lay-1],m_RectTable[lay].left(),m_RectTable[lay].top(),m_RectTable[lay].width(),m_RectTable[lay].height(),CopyROP); //m_BitmapTable is a QVector< QPixmap* >, m_RectTable is a QVector<QRect> tmp.begin(m_BitmapTable[lay]); if (lay==0) tmp.fillRect(m_RectTable[lay], *m_pBrush); OnDraw(&tmp,lay); tmp.end(); m_RectTable[lay].setRect(0,0,-1,-1); } } bitBlt(this, rcBounds.left(), rcBounds.top(),m_BitmapTable[m_LayerNb-1],rcBounds.left(), rcBounds.top(),rcBounds.width(), rcBounds.height(), CopyROP); } 

I tried replacing bitblt with drawPixmap , but the performance is very poor since I have to display the screen often.

Here is the new Qt5 code:

 void CAsdView::paintEvent ( QPaintEvent * Event) { QRect rcBounds=Event->rect(); QPainter tmp; for (int lay=0;lay<(int)m_RectTable.size();lay++) { if (!m_RectTable.at(lay).isEmpty()) { tmp2.begin(m_BitmapTable[lay]); if (lay != 0) { tmp.drawPixmap(m_RectTable[lay].left(), m_RectTable[lay].top(), *m_BitmapTable.at(lay - 1), m_RectTable[lay].left(), m_RectTable[lay].top(), m_RectTable[lay].width(), m_RectTable[lay].height());//TOCHECK m_BitmapTable[lay] = m_BitmapTable[lay - 1].copy(m_RectTable[lay]); } if (lay==0) tmp.fillRect(m_RectTable.at(lay), *m_pBrush); OnDraw(&tmp, lay); tmp.end(); m_RectTable[lay].setRect(0, 0, -1, -1); } } tmp.begin(this); tmp.drawPixmap(rcBounds.left(), rcBounds.top(), m_BitmapTable.at(m_LayerNb - 1), rcBounds.left(), rcBounds.top(), rcBounds.width(), rcBounds.height()); tmp.end(); } 
  • There are 3 layers for layers. Layer 0 is the deepest (background), layer 2 is the highest. This configuration is used to ensure that air traffic is always displayed at the top of the screen.

  • The OnDraw method draws elements that have changed since the last paintEvent, depending on the layer

Q: Do you have any ideas on how I could improve this paintEvent method to return to good behavior and again have good results with Qt5?

+5
source share
1 answer

I found the problem here.

drawPixmap / drawImage is the best bitblt alternative in Qt4 / Qt5. Unfortunately, I had some problems with the scaled () method of QPixmap (used in another piece of code not shown here ...), which brought me poor results. I had to switch from pixmap.resize () to pixmap.scaled () and I made a mistake here.

I changed it, and now I clearly have a good result. So for those who love me who are still interested, the best alternative in Qt for Bitblt is drawPixmap with QPainter.

+2
source

All Articles