【发布时间】:2015-07-16 20:06:22
【问题描述】:
我正在开发一个使用主 QGraphicsView 制作的 Qt 应用程序。
这个视图可以显示和切换不同的QgraphicsScenes。此应用程序需要始终在每个场景前面都有一个叠加层,因此最好的方法是通过 QGraphicsView 的setForegroundBrush() 方法进行叠加。
但我的叠加层是平铺图像,我可以在其中编辑源图像的不透明度和比例。
这是在我的 QGraphicsView 类构造函数中编写的代码:
QString imgPath("path/to/image.png");
QPixmap map(imgPath);
QPainter painter(this);
QRectF zone(0,0,map.width(),map.height());
painter.drawPixmap(zone,map,zone);
QBrush brush = painter.brush();
brush.setStyle(Qt::TexturePattern);
setForegroundBrush(brush);
但是不起作用,什么也没有显示。 我用 QPixmap 测试了一个简单的 QBrush,效果很好,但我需要使用 QPainter 才能编辑图像的不透明度。
【问题讨论】:
标签: qt qgraphicsview qpixmap