Qt5: From BitBlt to QPainter::drawImage
Qt5: From BitBlt to QPainter::drawImage
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方法的目的是什么?
谢谢你的帮助
相关文章:
- QPainter 将 QBrush 设置为 在 QT/C++ 中绘制文本
- QQuickPaintedItem 使用 QPainter 缓慢更新
- 警告 QPainter 内部油漆事件
- 如何使用Qpainter在Qt中绘制棋盘
- QPainter的QWidget滚动条
- Qt:在一个类中有一个QPainter对象的实例
- 将 QPainter 与 QCoreApplication 一起使用
- 定期使用 QPainter 绘图
- QPainter 绘制不一致
- 如何使用QPainter将多个Qwidgets在不同页面中打印到PDF
- 限制qpainter在pixmap上的图形
- 如何将 QPainter 和 OpenGL 与着色器并行使用 Qt5.9
- 如何在 Qt/hook QPainter 中渲染没有抗锯齿的 SVG 以避免抗锯齿?
- 如何从QMainWindow中的一组小部件上使用QPainter绘制特定的小部件
- 为什么 QPainter 在 QAbstractItemView::d ataChanged 中不起作用
- QPainter 未正确绘制文本
- 如何使用 QPainter 缩放文本以适合边界框
- 无法存储(保存)QPainter 映像
- 如何转移qpainter?(从出厂功能中移动对象)
- Qt5: From BitBlt to QPainter::drawImage