Qt5: From BitBlt to QPainter::drawImage

Qt5: From BitBlt to QPainter::drawImage

本文关键字:QPainter drawImage to BitBlt From Qt5      更新时间:2023-10-16

StackOverflow专家你好,

我对Qt很陌生,我目前正在从QT4升级到QT5的专业应用程序。

我有一个bitblt的问题,需要升级到QPainter::drawImage。

应用程序正在编译和运行,但我只有一个黑色的图像显示,而我应该有绿色的线画在这个黑色的图像。这就像背景总是在前面,没有什么可以画在它上面。

这是我之前的代码

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

我替换了:

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);

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

:

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

这个paintEvent函数用于显示我的应用程序的整个元素,如弹出窗口等…(图层表示不同的图形层)。

    我升级bitblt的方式有问题吗?
  • 我应该有一个不同的架构,因为bitblt和drawImage的工作方式不一样吗?

如果有任何遗漏的信息,以更好地了解我的问题,请随时问我!

非常感谢你的帮助!

多亏了Frank Osterfeld。问题来自这些begin()和end()方法。可能没有摆放好。我不知道它们到底是用来做什么的,但我把它们移走了,现在看起来工作得很好。

下面是新的代码:

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

我仍然有一个问题,QPainter::begin和QPainter::end方法的目的是什么?

谢谢你的帮助