0

Hello StackOverflow experts,

I am pretty noob at Qt and I am currently upgrading a profesionnal application from QT4 to QT5.

I have a problem with a bitblt that a need to upgrade to QPainter::drawImage.

The application is compiling and running but I only have a black image displayed whereas I should have green lines painted on this black image. It is like the background is always at the front and nothing can be paint on top of it.

Here is my previous code

void View::paintEvent ( QPaintEvent * Event)
{   
    QRect   rcBounds=Event->rect();
    QPainter tmp(this);

    for (int lay=0;lay<(int)m_RectTable.size();lay++)
    {
        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(), QPainter::CompositionMode_SourceOver);
            }

            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(), QPainter::CompositionMode_SourceOver); 
}

And I replaced:

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(), QPainter::CompositionMode_SourceOver);

and

bitBlt(this, rcBounds.left(), rcBounds.top(),m_BitmapTable[m_LayerNb-1],rcBounds.left(), rcBounds.top(),rcBounds.width(), rcBounds.height(), QPainter::CompositionMode_SourceOver); 

with:

tmp.drawPixmap(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());
    tmp.drawPixmap(rcBounds.left(), rcBounds.top(), *m_BitmapTable[m_LayerNb - 1], rcBounds.left(), rcBounds.top(), rcBounds.width(), rcBounds.height());

This paintEvent function is used to display the entire elements of my application such as Pop-up Window etc... (lay is for the different graphical layers).

  • Is there something wrong with my way of upgrading bitblt ?
  • Should I have a different architecture because bitblt and drawImage are not working the same way ?

If there is any missing information to have a better understanding of my problem feel free to ask me !

Thank you very much for your help !

Robert Jones
  • 587
  • 7
  • 25

1 Answers1

0

I figured it out thanks to Frank Osterfeld. The problem was coming from these beign() and end() methods. There were probably not well placed. I don't know exactly what they are used for but I removed those and it seems to work pretty well now.

So here is the new code:

void View::paintEvent ( QPaintEvent * Event)
{
    QRect   rcBounds=Event->rect();

    QPainter tmp(this);

    for (int lay=0;lay<(int)m_RectTable.size();lay++)
    {
        if (!m_RectTable[lay].isEmpty())
        {          
            if (lay != 0)
            {
                tmp.drawPixmap(m_RectTable[lay], *m_BitmapTable.at(lay - 1), m_RectTable[lay]);
            }

            if (lay==0)
                tmp.fillRect(m_RectTable[lay], *m_pBrush);

            OnDraw(&tmp, lay);
            m_RectTable[lay].setRect(0, 0, -1, -1);
        }
    }
    tmp.drawPixmap(rcBounds, *m_BitmapTable.at(m_LayerNb - 1), rcBounds);
}

I still have one question though, what are QPainter::begin and QPainter::end methods intended for ?

Thank you for your help

Robert Jones
  • 587
  • 7
  • 25