QT5:使用drawPixMap()在另一个矩形的顶部绘制矩形
QT5: Drawing rect on top of another rect using drawPixMap()
我是否正确使用drawPixmap()
?
从本质上讲,我的目标是获取一个平铺集图像,并用自定义平铺图像替换单个平铺。
我可以在屏幕上加载这两个图像,但当我调用drawPixmap()
时,原始图像根本不会改变。
提前谢谢。
void replaceCustomTile(QPixmap custom, QPixmap target, int whichTile) {
QRect rect(0, 0 + (squareTileSize * whichTile), squareTileSize, squareTileSize);
QRect customRect = custom.rect();
QPainter painter(this);
painter.drawPixmap(rect, target, customRect);
painter.end();
}
编辑:
这就是replaceCustomTile的名称:
QPixmap terrainTiles(":/static/Terrain.png");
QPixmap customTile(":/static/Smiles.png");
replaceCustomTile(customTile, terrainTiles, 0);
要通过this
初始化QPainter
,如果您想在某个小部件上绘制它,则必须从小部件paintEvent(QPaintEvent *)
调用它。因此,在这种情况下,应该从事件处理程序调用replaceCustomTile()
。
要在另一个像素图的顶部绘制某个像素图,QPainter
应使用QPainter::begin()
:由目标像素图初始化
QPainter painter;
painter.begin(&target);
painter.drawPixmap(rect, custom);
painter.end();
上述代码通过CCD_ 11将CCD_ 9绘制为给定的CCD_。对target
进行了修改。
相关文章:
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 绘制顺时针三角形,重新排序点
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 程序顶部的声明与定义(最佳实践)
- SFML 文本未绘制在窗口上
- 如何在快板的屏幕中显示子位图的绘制?
- 如何绘制自定义形状的元素?
- 用SFML在屏幕顶部(Windows)绘制
- 在第三方应用程序的窗口顶部绘制
- OpenGl 在图块地图C++的顶部绘制
- QT5:使用drawPixMap()在另一个矩形的顶部绘制矩形
- 在另一个子窗口的顶部绘制一个子窗口
- 在直接绘制全屏应用程序的顶部显示另一个应用程序
- Qt,绘制顶部的标签与图像作为背景