我在 QPixmap 上使用 QPainter 作为绘画框架。QGraphicsScene 持有 QPixmap。这幅画效果很好。但问题是当我更改 QGraphicsView 的背景颜色时,它不会反映在屏幕上。我尝试了 QPixmap::fill(Qt::tranparent)。但它没有用。
我怎样才能实现这种透明的QPixmap?提前谢谢?
int main(int argc, char **argv){
QApplication a(argc, argv);
QMainWindow *win = new QMainWindow();
win->resize(600,600);
win->move(80,80);
win->show();
QGraphicsScene *scene = new QGraphicsScene(win);
QGraphicsView view(scene,win);
view.resize(590,590);
view.setBackgroundBrush(QColor(rand()%255,rand()%255, rand()%255, 255));
view.show();
QPixmap *pix = new QPixmap(600,600);
pix->fill(&view,QPoint(0,0));
QGraphicsPixmapItem *item = scene->addPixmap(*pix);
QPainter *painter = new QPainter(pix);
int count=10;
while(count){
painter->setPen((*new QColor(rand()%255,rand()%255, rand()%255, 255)));
painter->setBrush(QColor(rand()%255,rand()%255, rand()%255, 255));
painter->drawRect(rand()%300, rand()%300, rand()%300, rand()%300);
item->setPixmap(*pix);
a.processEvents(0x00);
count--;
}
return a.exec();
}